Compare commits

...

11 Commits
v1.5 ... main

Author SHA1 Message Date
Aliberk Sandıkçı a996fc3af3 Update index.php
ufak bir değişiklik, verileri güncelleyen samimi arkadaşım Ömer Arda (Kelo)'ya verileri yanlış girdiğinde Web konsolda gözükecek not değiştirildi :)
2024-05-16 15:09:40 +03:00
Aliberk Sandıkçı 13bc5df3e7
notes 2024-01-15 17:24:01 +03:00
Aliberk Sandıkçı 911a66dc7b
prevent same person two day 2024-01-13 01:00:39 +03:00
Aliberk Sandıkçı 3099ab1244
update styles and cautions 2024-01-10 19:06:33 +03:00
Aliberk Sandıkçı 59f2c716dd
sort persons 2024-01-09 22:42:39 +03:00
Aliberk Sandıkçı 412bcc1035
test data before use 2024-01-08 19:05:46 +03:00
Aliberk Sandıkçı 041b6a2634
mini update 2024-01-08 17:45:50 +03:00
Aliberk Sandıkçı 30be555616
add new effect 2024-01-07 21:37:14 +03:00
Aliberk Sandıkçı 8772320cb1
feat: add frontend data reload option 2024-01-07 16:46:33 +03:00
Aliberk Sandıkçı 090cec8242
hide tebrisk if new day 2024-01-07 16:27:11 +03:00
Aliberk Sandıkçı 9cc4e065c5
update notice logic 2024-01-07 16:21:35 +03:00
4 changed files with 178 additions and 16 deletions

View File

@ -8,6 +8,17 @@
border: 1px solid white;
}
.latest-guess {
visibility: hidden;
opacity: 0;
}
.latest-guess.fade {
visibility: inherit;
opacity: 1;
transition: opacity 1s;
}
.innot {
text-align: center;
}

109
index.php
View File

@ -41,12 +41,16 @@
<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>
<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>
<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;">
<div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span>
</div>
</div>
<div style="text-align: center;align-self:center;"><a href="https://asandikci.com/bagis/">Bana Bi' Kahve Ismarla </a></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>
</article>
<footer>
@ -102,11 +106,54 @@
}, 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>
function isSameDay(a, b) {
return a.toDateString() == b.toDateString();
}
getPreviousData();
if (localStorage.getItem("win") == null) {
localStorage.setItem("win", "none");
}
@ -131,6 +178,7 @@
localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess");
localStorage.removeItem("win");
document.getElementById("tebriks").style.display = "none";
}
localStorage.setItem("latest_visit", date);
}
@ -196,6 +244,8 @@
tr.appendChild(th);
}
// REVIEW Daha optimize ve karışık olmayacak şekilde yazılabilir
for (let i = gj["Guesses"].length - 1; i >= 0; i--) {
// revit = gj["Guesses"].length - i - 1;
const tr = document.createElement("tr");
@ -208,7 +258,12 @@
if (innerFlag) crit_num++;
const td = document.createElement("td");
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 (i == gj["Guesses"].length - 1 && flagSame == 0) {
td.classList.add("latest-guess");
}
switch (indata[key][0]) {
case 0:
td.classList.add("type0");
@ -236,10 +291,23 @@
}
}
// console.log(gj);
if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
// console.warn(crit_num, true_num);
var lat = document.getElementsByClassName("latest-guess");
var le = lat.length;
function delay(time) {
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").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
localStorage.setItem("win", "winned");
@ -247,6 +315,11 @@
callConfetti();
}
}
// console.log(gj);
if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
yepwin();
}
// NOTICES
@ -263,8 +336,8 @@
} else {
innot = document.createElement("p");
innot.classList.add("innot");
innot_text = document.createTextNode(element);
innot.appendChild(innot_text);
innot_text = element;
innot.innerHTML = innot_text;
notic.appendChild(innot);
}
});
@ -385,9 +458,25 @@
}
const persons2 = <?php echo json_encode(getAllPersonNames(), JSON_UNESCAPED_UNICODE) ?>;
persons2.sort();
autocomplete(document.getElementById("mainInput"), persons2);
</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>

1
src/previous.php Normal file
View File

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

View File

@ -3,6 +3,7 @@
use Yosymfony\Toml\Toml;
include __DIR__ . '/todays.php';
include __DIR__ . '/previous.php';
include __DIR__ . '/../config.php';
require __DIR__ . '/../vendor/autoload.php';
@ -10,13 +11,29 @@ $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;
}
function updateRemoteData()
{
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.";
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);
@ -25,25 +42,41 @@ function updateRemoteData()
chown("$file", $APP_NAME);
parseTOML(); // not necessary
echo "success";
}
# 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)
function chooseTodayPerson()
{
global $APP_NAME;
global $TODAYS_PERSON;
$data = parseTOML()["data"];
backupPreviousPerson($TODAYS_PERSON);
$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];
// TODO control each person if already choosed recently? (make all persons avaliable AFTER all of them choosed )
$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";
@ -52,6 +85,25 @@ function chooseTodayPerson()
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
function getAllPersonNames()
{
@ -189,3 +241,12 @@ function parseTOML()
$array = $parser::ParseFile(__DIR__ . "/../data.toml");
return $array;
}
if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") {
updateRemoteData();
}
if ($_POST['getPreviousPerson'] != null && $_POST['getPreviousPerson'] == "yes") {
echo getPreviousPersonName();
}