Compare commits

..

No commits in common. "main" and "v1.1" have entirely different histories.
main ... v1.1

7 changed files with 62 additions and 328 deletions

2
.gitignore vendored
View file

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

View file

@ -8,17 +8,6 @@
border: 1px solid white; border: 1px solid white;
} }
.latest-guess {
visibility: hidden;
opacity: 0;
}
.latest-guess.fade {
visibility: inherit;
opacity: 1;
transition: opacity 1s;
}
.innot { .innot {
text-align: center; text-align: center;
} }
@ -38,6 +27,8 @@
} }
} }
.guess-tr {}
.guess-th { .guess-th {
border: aliceblue 3px solid; border: aliceblue 3px solid;
} }
@ -78,48 +69,4 @@
.type12::after { .type12::after {
content: "👆" 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

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
set -x
rm -rf build/ rm -rf build/
mkdir build mkdir build
composer update composer update
@ -13,11 +12,6 @@ rm README.md
rm yurdle_server.tar.gz rm yurdle_server.tar.gz
rm buildzip.sh rm buildzip.sh
rm dockerserver.sh rm dockerserver.sh
rm config.php
rm composer.json
rm composer.lock
rm -rf build/ rm -rf build/
sleep 1 sleep 1
tar czf ../yurdle_server.tar.gz ./* tar czf ../yurdle_server.tar.gz ./*
set +x

190
index.php
View file

@ -25,9 +25,9 @@
min-height: 100vh;"> min-height: 100vh;">
<form class="centered" style="margin-top: 10vh;" action="index.php" method="post"> <form class="centered" style="margin-top: 10vh;" action="index.php" method="post">
<label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label> <label style="margin-bottom:1vh;" for="mainInput">Yurtlu Öğrencinin İsmini Giriniz</label>
<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> <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>
</form> </form>
<div id="tebriks" style="display: none;"> <div id="tebriks">
</div> </div>
<div id="tahminler"> <div id="tahminler">
@ -38,19 +38,13 @@
<div id="notices"> <div id="notices">
</div> </div>
<div id="tsparticles"></div>
<hr style="width: 100%; box-sizing: border-box;"> <hr style="width: 100%; box-sizing: border-box;">
<div style="margin-top:5px;text-align:center;"> <b>Dünün Şanslı Kişisi:</b> <span id="previous-person"><i>yükleniyor</i></span></div> <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;">
<div id="sorumli" style="margin-top:5px;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;">
<div style="margin-top:5px;text-align:center;">Fikir için <b>Cem Deniz Akdeniz</b>'e Teşekkürler !</div>
<hr style="width: 100%; box-sizing: border-box;"> <hr style="width: 100%; box-sizing: border-box;">
<div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span> <div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span>
</div> </div>
</div> </div>
<div style="text-align: center;align-self:center;background-color: darkblue;border-radius:10px; padding:1px;"><a style="color: orange;font-weight:800;" href="https://asandikci.com/bagis/">👉 Bana Bi' Kahve Ismarla </a></div> <div style="text-align: center;align-self:center;"><a href="https://asandikci.com/bagis/">Bana Bi' Kahve Ismarla </a></div>
</article> </article>
<footer> <footer>
@ -60,109 +54,19 @@
</body> </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 updateData() {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = xmlHttp.responseText
if (response.includes("parseError")) {
console.error("VERİLER YANLIŞ ŞEKİLDE GİRİLMİŞ, LÜTFEN ifl/YurdleBackend PROJESİNDEKİ VERİ DOSYASINI KONTROL EDİNİZ");
console.warn(response);
} else if (response.includes("fileError")) {
console.error("VERİ DOSYASI SUNUCUDA BULUNAMADI, SUNUCUYU KONTROL EDİNİZ");
console.warn(response);
} else if (response.includes("success")) {
console.info("VERİLER BAŞARIYLA GÜNCELLENDİ")
} else {
console.warn("VERİ GÜNCELLENİRKEN BİR HATA OLUŞTU, SAYFAYI YENİLEMEYİ DENEYİN");
}
}
};
params = "updateData=yes";
xmlHttp.open("POST", "src/server.php", true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(params);
flag = true;
return;
}
function getPreviousData() {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = xmlHttp.responseText;
document.getElementById("previous-person").innerHTML = "<b style='color:red';>" + response + "</b>";
console.debug("Dünün Şanslı Kişisi: " + response);
}
};
params = "getPreviousPerson=yes";
xmlHttp.open("POST", "src/server.php", true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(params);
flag = true;
}
</script>
<script> <script>
function isSameDay(a, b) { function isSameDay(a, b) {
return a.toDateString() == b.toDateString(); return a.toDateString() == b.toDateString();
} }
getPreviousData();
if (localStorage.getItem("win") == null) { if (localStorage.getItem("win") == null) {
localStorage.setItem("win", "none"); localStorage.setItem("win", "none");
} }
flagConf = 1;
document.getElementById("tebriks").style.display = "none"; document.getElementById("tebriks").style.display = "none";
if (localStorage.getItem("win") != null && localStorage.getItem("win") === "winned") { if (localStorage.getItem("win") != null && localStorage.getItem("win") === "winned") {
console.log(localStorage.getItem("win"));
document.getElementById("tebriks").style.display = "block"; document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!" document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
flagConf = 0;
} }
// LOCAL STORAGE AND GUESS HANDLING // LOCAL STORAGE AND GUESS HANDLING
@ -172,18 +76,14 @@
} else { } else {
latest_visit = localStorage.getItem("latest_visit"); latest_visit = localStorage.getItem("latest_visit");
if (isSameDay(new Date(latest_visit), date)) { if (isSameDay(new Date(latest_visit), date)) {
console.debug("Kullanıcı Son Girişi İle Aynı Günde"); console.log("same day!");
} else { } else {
console.debug("Kullanıcı Farklı Bir Günde Giriş Yaptı, Statlar Sıfırlanıyor"); console.log("different day!");
localStorage.removeItem("guesses"); localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess");
localStorage.removeItem("win");
document.getElementById("tebriks").style.display = "none";
} }
localStorage.setItem("latest_visit", date); localStorage.setItem("latest_visit", date);
} }
<?php include __DIR__ . '/src/server.php'; ?> <?php include './src/server.php'; ?>
current_guess = "<?php current_guess = "<?php
if ($_POST['mainInput'] != null) { if ($_POST['mainInput'] != null) {
echo htmlspecialchars($_POST['mainInput']); echo htmlspecialchars($_POST['mainInput']);
@ -192,7 +92,7 @@
flagSame = 0; flagSame = 0;
if (localStorage.getItem("latest_guess") != null) { if (localStorage.getItem("latest_guess") != null) {
if (current_guess == localStorage.getItem("latest_guess")) { if (current_guess == localStorage.getItem("latest_guess")) {
console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!! (veya sayfayı yenilemiş/geri gelmiş de olabilirsiniz)") console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!!")
flagSame = 1; flagSame = 1;
} }
localStorage.setItem("latest_guess", current_guess); localStorage.setItem("latest_guess", current_guess);
@ -208,17 +108,16 @@
var gj = JSON.parse('{"Guesses":[], "Values":[]}'); // guess json var gj = JSON.parse('{"Guesses":[], "Values":[]}'); // guess json
if (localStorage.getItem("guesses") != null) { if (localStorage.getItem("guesses") != null) {
console.debug("Local Storage Succesfully Get!"); console.log("local storage get!");
gj = JSON.parse(localStorage.getItem("guesses")); gj = JSON.parse(localStorage.getItem("guesses"));
} }
if (current_guess != "" && flagSame == 0) { if (current_guess != "" && flagSame == 0) {
gj["Guesses"].push(current_guess); gj["Guesses"].push(current_guess);
console.debug("Denenen Kişi: " + current_guess); console.warn(current_guess);
gj["Values"].push(<?php if ($_POST['mainInput'] != null) { gj["Values"].push(<?php if ($_POST['mainInput'] != null) {
$inner_cg = htmlspecialchars($_POST['mainInput']); $inner_cg = htmlspecialchars($_POST['mainInput']);
echo "'" . json_encode(comparePerson(reversePerson($inner_cg)), JSON_UNESCAPED_UNICODE) . "'";
} }
?>); echo "'" . json_encode(comparePerson(reversePerson($inner_cg)), JSON_UNESCAPED_UNICODE) . "'"; ?>);
localStorage.setItem("guesses", JSON.stringify(gj)); localStorage.setItem("guesses", JSON.stringify(gj));
} }
@ -244,8 +143,6 @@
tr.appendChild(th); tr.appendChild(th);
} }
// REVIEW Daha optimize ve karışık olmayacak şekilde yazılabilir
for (let i = gj["Guesses"].length - 1; i >= 0; i--) { for (let i = gj["Guesses"].length - 1; i >= 0; i--) {
// revit = gj["Guesses"].length - i - 1; // revit = gj["Guesses"].length - i - 1;
const tr = document.createElement("tr"); const tr = document.createElement("tr");
@ -253,17 +150,12 @@
table.appendChild(tr); table.appendChild(tr);
indata = JSON.parse(gj["Values"][i]); indata = JSON.parse(gj["Values"][i]);
// console.warn(indata); console.warn(indata);
for (const key in criterias) { for (const key in criterias) {
if (innerFlag) crit_num++; if (innerFlag) crit_num++;
const td = document.createElement("td"); const td = document.createElement("td");
const td_text = document.createTextNode(indata[key][1]); const td_text = document.createTextNode(indata[key][1]);
// FIXME isim_soyisim renkli olmasın diye kontrol yapılıyor ama bu durumda isim soyisim haricinde diğer tüm özellikleri aynı olan başka biri daha olursa onu da doğru sayar !!!
if (key != "isim_soyisim") { if (key != "isim_soyisim") {
if (i == gj["Guesses"].length - 1 && flagSame == 0) {
td.classList.add("latest-guess");
}
switch (indata[key][0]) { switch (indata[key][0]) {
case 0: case 0:
td.classList.add("type0"); td.classList.add("type0");
@ -291,34 +183,13 @@
} }
} }
var lat = document.getElementsByClassName("latest-guess"); console.log(gj);
var le = lat.length; if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
function delay(time) { console.warn(crit_num, true_num);
return new Promise(resolve => setTimeout(resolve, time));
}
async function delayeffect() {
for (let i = 0; i < lat.length; i++) {
const element = lat[i];
await delay(750);
element.classList.toggle('fade');
}
}
delayeffect();
async function yepwin() {
await delay(5000);
document.getElementById("tebriks").style.display = "block"; document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!" document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
localStorage.setItem("win", "winned"); localStorage.setItem("win", "winned");
if (flagConf) {
callConfetti();
}
}
// console.log(gj);
if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
yepwin();
} }
@ -336,8 +207,8 @@
} else { } else {
innot = document.createElement("p"); innot = document.createElement("p");
innot.classList.add("innot"); innot.classList.add("innot");
innot_text = element; innot_text = document.createTextNode(element);
innot.innerHTML = innot_text; innot.appendChild(innot_text);
notic.appendChild(innot); notic.appendChild(innot);
} }
}); });
@ -346,7 +217,7 @@
// UPDATES // UPDATES
const updates = <?php echo json_encode(sendDataDate()) ?>; const updates = <?php echo json_encode(sendDataDate()) ?>;
document.getElementById("latest-data").innerHTML = updates[0]; document.getElementById("latest-data").innerHTML = updates[0];
console.info("Günün Kişisi, Son Güncelleme Zamanı: " + updates[1]); console.log("günün kişisi güncellenme zamanı: " + updates[1]);
/// AUTOCOMPLETE /// /// AUTOCOMPLETE ///
@ -458,25 +329,8 @@
} }
const persons2 = <?php echo json_encode(getAllPersonNames(), JSON_UNESCAPED_UNICODE) ?>; const persons2 = <?php echo json_encode(getAllPersonNames(), JSON_UNESCAPED_UNICODE) ?>;
persons2.sort();
autocomplete(document.getElementById("mainInput"), persons2); autocomplete(document.getElementById("mainInput"), persons2);
</script> </script>
<script>
var t = setInterval(tick, 1000);
function tick() {
var curTime = new Date();
if (curTime.getHours() == 0 && curTime.getMinutes() == 0 && curTime.getSeconds() > 1 && curTime.getSeconds() < 3) {
console.debug("Kullanıcının Ekranııkken Farklı Bir Güne Geçiş Yapıldı, Statlar Sıfırlanıyor ve Kullanıcı Bilgilendiriliyor");
localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess");
localStorage.removeItem("win");
document.getElementById("tebriks").style.display = "none";
document.getElementById("tahminler").innerHTML = "<h2 style='text-align:center;'>Gece Yarısını Geçtiniz, Lütfen Sayfayı Yenile<span style='color:red;'>ME</span>den direkt yeni tahminizde bulununuz👆</h2><p style='text-align:center;'>Kullanıcının cihazının saati baz alınmıştır, sunucunun yenilenmesi için birkaç saniye daha beklemeniz gerekebilir</p>"
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/confetti@3.0.3/tsparticles.confetti.bundle.min.js"></script>
</html> </html>

View file

@ -1 +0,0 @@
<?php $PREVIOUS_PERSON = "aliberk_sandikci24";

View file

@ -2,111 +2,58 @@
use Yosymfony\Toml\Toml; use Yosymfony\Toml\Toml;
include __DIR__ . '/todays.php'; include 'todays.php';
include __DIR__ . '/previous.php';
include __DIR__ . '/../config.php';
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
$parser = new Toml(); $parser = new Toml();
$dock_local_test = 1;
# Fetch Remote data and update data.toml (running each 10 min with cronjob)
function testData($toml)
{
global $parser;
try {
$array = $parser::Parse($toml);
} catch (Exception $e) {
$ans = 'Caught exception: ' . $e->getMessage() . "\n";
return $ans;
}
return 0;
}
# Fetch remote data each 1 hour
function updateRemoteData() function updateRemoteData()
{ {
global $DATAACCESS_TOKEN; # PREREQUIRITIES Create a cronjob or a systemd service for update it regularly !
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 "fileError: Could not read the file or could not get the file from server";
return;
} else if (testData($string) != 0) {
echo "parseError: " . testData($string);
return;
} else {
$file = __DIR__ . "/../data.toml";
file_put_contents($file, $string, LOCK_EX);
}
chmod("$file", 0700);
chown("$file", $APP_NAME);
parseTOML(); // not necessary # GET FROM GIT WITH ACCESS TOKEN AND SAVE TO data.toml
echo "success";
# MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!!
parseTOML(); # parse again after update
} }
# get random person
function randomizerr($array)
{
srand();
$random_number = random_int(0, count($array) - 1);
$choosen = $array[$random_number];
return $choosen;
}
# Choose the todays person (running each day with cronjob) # Choose the todays person, everyday TSI 03:00
function chooseTodayPerson() function chooseTodayPerson()
{ {
global $APP_NAME; # PREREQUIRIITES with cronjob or systemd, run this function everyday TSI 03.00
global $TODAYS_PERSON;
$data = parseTOML()["data"];
backupPreviousPerson($TODAYS_PERSON); # parse toml
$personArr = array(); # get users array length
foreach ($data as $key => $value) {
array_push($personArr, $key);
}
# get a random number
# make this person todays person, change $TODAYS_PERSON variable in today.php
$choosen = randomizerr($personArr);
echo $choosen . " - " . $TODAYS_PERSON;
while ($choosen == $TODAYS_PERSON) {
echo "!!!";
$choosen = randomizerr($personArr);
echo $choosen . " - " . $TODAYS_PERSON;
}
$string = "<?php \$TODAYS_PERSON = \"$choosen\";";
$file = __DIR__ . "/todays.php";
file_put_contents($file, $string, LOCK_EX);
chmod("$file", 0700);
chown("$file", $APP_NAME);
}
# Backup previous person to previous.php file
function backupPreviousPerson($previous)
{
global $APP_NAME;
$string = "<?php \$PREVIOUS_PERSON = \"$previous\";";
$file = __DIR__ . "/previous.php";
file_put_contents($file, $string, LOCK_EX);
chmod("$file", 0700);
chown("$file", $APP_NAME);
}
# get Previous Person Name (isi_soyisim)
function getPreviousPersonName()
{
global $PREVIOUS_PERSON;
return parseTOML()["data"][$PREVIOUS_PERSON]["isim_soyisim"];
} }
# Send all person names to frontend # Send all person names to frontend
function getAllPersonNames() 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"]; $data = parseTOML()["data"];
$arr = array(); $arr = array();
foreach ($data as $d) { foreach ($data as $d) {
@ -144,6 +91,7 @@ function sendDataDate()
$arr[1] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/" . $filename)); $arr[1] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/" . $filename));
} }
return $arr; return $arr;
} }
@ -219,7 +167,7 @@ function compareARR($guess, $todays, $krit)
if ($equalNum == 0) { if ($equalNum == 0) {
return 0; return 0;
} else if ($equalNum == count($todays) && $equalNum == count($guess)) { } else if ($equalNum == count($todays)) {
return 2; return 2;
} else if ($equalNum >= 1) { } else if ($equalNum >= 1) {
return 1; return 1;
@ -238,15 +186,8 @@ function getAPersonStats($person)
function parseTOML() function parseTOML()
{ {
global $parser; global $parser;
$array = $parser::ParseFile(__DIR__ . "/../data.toml"); $array = $parser::ParseFile("data.toml");
return $array; return $array;
} }
comparePerson('aliberk_sandikci24');
if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") {
updateRemoteData();
}
if ($_POST['getPreviousPerson'] != null && $_POST['getPreviousPerson'] == "yes") {
echo getPreviousPersonName();
}

View file

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