Compare commits

..

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

10 changed files with 20 additions and 1010 deletions

5
.gitignore vendored
View file

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

View file

@ -1,125 +0,0 @@
#tebriks {
text-align: center;
font-size: larger;
font-weight: 800;
color: blue;
background-color: coral;
padding: 3px;
border: 1px solid white;
}
.latest-guess {
visibility: hidden;
opacity: 0;
}
.latest-guess.fade {
visibility: inherit;
opacity: 1;
transition: opacity 1s;
}
.innot {
text-align: center;
}
.guess-table {
width: 100%;
display: table;
overflow-x: auto;
-ms-overflow-style: none;
scrollbar-width: none;
}
@media screen and (max-device-width: 1000px) {
.guess-table {
display: block;
overflow-x: auto;
}
}
.guess-th {
border: aliceblue 3px solid;
}
.guess-td {
text-align: center;
border: aliceblue 1px solid;
}
.type0 {
background-color: red;
font-weight: 800;
}
.type1 {
background-color: orange;
color: darkblue;
font-weight: 500;
}
.type2 {
background-color: green;
}
.type10 {
background-color: red;
font-weight: 800;
}
.type10::after {
content: "👇"
}
.type12 {
background-color: red;
font-weight: 800;
}
.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

@ -1,10 +1,7 @@
#!/bin/bash
set -x
rm -rf build/
mkdir build
composer update
composer install
cp -r ./* build/
cp -r ../YurdleBackend/* build/
cd build/ || exit
@ -13,11 +10,6 @@ rm README.md
rm yurdle_server.tar.gz
rm buildzip.sh
rm dockerserver.sh
rm config.php
rm composer.json
rm composer.lock
rm -rf build/
sleep 1
tar czf ../yurdle_server.tar.gz ./*
set +x
tar czf ../yurdle_server.tar.gz ./*

View file

@ -1,23 +0,0 @@
{
"name": "asandikci/yurdle",
"description": "yurdle package",
"type": "project",
"require": {
"yosymfony/toml": "^1.0"
},
"require-dev": {
"yosymfony/toml": "^1.0"
},
"license": "GPL3.0",
"autoload": {
"psr-4": {
"Asandikci\\Yurdle\\": "src/"
}
},
"authors": [
{
"name": "asandikci",
"email": "git@aliberksandikci.com.tr"
}
]
}

129
composer.lock generated
View file

@ -1,129 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "add81bece92d883faaa7f717e5256419",
"packages": [
{
"name": "yosymfony/parser-utils",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://github.com/yosymfony/parser-utils.git",
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yosymfony/parser-utils/zipball/00bec9a12722b21f2baf7f9db35f127e90c162c9",
"reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"phpunit/phpunit": "^6"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Yosymfony\\ParserUtils\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Victor Puertas",
"email": "vpgugr@gmail.com",
"homepage": "http://yosymfony.com"
}
],
"description": "Parser utilities",
"homepage": "http://github.com/yosymfony/toml",
"keywords": [
"lexer",
"parser"
],
"support": {
"issues": "https://github.com/yosymfony/parser-utils/issues",
"source": "https://github.com/yosymfony/parser-utils/tree/master"
},
"time": "2018-06-29T15:31:11+00:00"
},
{
"name": "yosymfony/toml",
"version": "v1.0.4",
"source": {
"type": "git",
"url": "https://github.com/yosymfony/toml.git",
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yosymfony/toml/zipball/bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
"reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e",
"shasum": ""
},
"require": {
"php": ">=7.1",
"yosymfony/parser-utils": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Yosymfony\\Toml\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Victor Puertas",
"email": "vpgugr@gmail.com",
"homepage": "http://yosymfony.com"
}
],
"description": "A PHP parser for TOML compatible with specification 0.4.0",
"homepage": "http://github.com/yosymfony/toml",
"keywords": [
"mojombo",
"parser",
"toml"
],
"support": {
"issues": "https://github.com/yosymfony/toml/issues",
"source": "https://github.com/yosymfony/toml/tree/master"
},
"time": "2018-08-08T15:08:14+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.6.0"
}

View file

@ -10,23 +10,23 @@ MOUNT_PATH="/source" # binded mount path in nginx docker
SCRIPT_NAME="dockerserver.sh" # name of the *this* file
SCRIPT_DIR="Yurdle" # containing directory of the *this* file
BUILD_DIR="." # build results of local source code (insert a dot (.) if you do not need to build your application)
# DATABASE_TYPE="postgresql" # database type, either mysql or postgresql
MAIN_NAME="yurdle" # main program name
PORT1="8000" # TODO what is the difference between 8000 and 80
DATABASE_TYPE="postgresql" # database type, either mysql or postgresql
MAIN_NAME="yurdle" # main program name
PORT1="8000" # TODO what is the difference between 8000 and 80
PORT2="80"
WEB_ROOT_DIR="/usr/share/nginx/html/" # public web root dir
WEB_SERVER_DIR="/usr/share/nginx/server/" # private server root dir
SECRET_SERVER="false" # add secret server to $WEB_ROOT_DIR/../$SECRET_SERVER_FOLDER
SECRET_SERVER="true" # add secret server to $WEB_ROOT_DIR/../$SECRET_SERVER_FOLDER
SECRET_SERVER_LOCAL_RELATIONAL_PATH="../YurdleBackend" # local path
SERVER_BUILD_DIR="." # server build dir
# __DB_NAME__="localdb"
# __DB_USER__="dbuser"
# __DB_PWD__="dbpass"
__DB_NAME__="localdb"
__DB_USER__="dbuser"
__DB_PWD__="dbpass"
PHP_VERSION="8.2"
ACTIVE_SERVICES=("nginx" "php$PHP_VERSION-fpm") # services
ACTIVE_SERVICES=("nginx" "php$PHP_VERSION-fpm" "postgresql") # services
############################
############################
@ -60,7 +60,6 @@ class Config
const DB_NAME = '$__DB_NAME__';
const DB_USERNAME = '$__DB_USER__';
const DB_PASSWORD = '$__DB_PWD__';
const DATAACCESS_TOKEN = 'LOCAL';
}
"""
@ -163,7 +162,7 @@ _restart() {
_reconf() {
_head "RECONFIGURATION"
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_DIR/config.php"
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_SERVER_DIR/config.php"
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/$PHP_VERSION/fpm/pool.d/$MAIN_NAME.conf"
_end "RECONFIGURATION"
@ -193,10 +192,8 @@ _update_conf() {
_refresh_folders() {
rm -rf $WEB_ROOT_DIR
mkdir -p $WEB_ROOT_DIR
if [[ $SECRET_SERVER == "true" ]]; then
rm -rf $WEB_SERVER_DIR
mkdir -p $WEB_SERVER_DIR
fi
rm -rf $WEB_SERVER_DIR
mkdir -p $WEB_SERVER_DIR
}
_setup_database() {
@ -217,10 +214,8 @@ _folder_permissions() {
useradd -g $MAIN_NAME $MAIN_NAME
cd $WEB_ROOT_DIR || exit
chown $MAIN_NAME:nginx -R .
if [[ $SECRET_SERVER == "true" ]]; then
cd $WEB_SERVER_DIR || exit
chown $MAIN_NAME:nginx -R .
fi
cd $WEB_SERVER_DIR || exit
chown $MAIN_NAME:nginx -R .
}
if [[ $# -eq 0 ]]; then
@ -296,9 +291,8 @@ elif [[ $1 == "docker" ]]; then
fi
apt install php php-fpm php-cli -y
locale-gen tr_TR
# _setup_database
_setup_database
_reconf

450
index.php
View file

@ -9,7 +9,6 @@
<meta name="author" content="Aliberk Sandıı">
<link rel="stylesheet" href="/assets/css/main.css">
<link rel="stylesheet" href="/assets/css/yurdle.css">
<title>Yurdle | İFL</title>
</head>
@ -21,36 +20,13 @@
</header>
<article class="sections">
<div class="section" style="height: max-content;
min-height: 100vh;">
<form class="centered" style="margin-top: 10vh;" action="index.php" method="post">
<div class="section" style="height:100vh">
<form class="centered" style="margin-top: 10vh;">
<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>
<input class="input" type="text" id="mainInput" name="mainInput" />
</form>
<div id="tebriks" style="display: none;">
</div>
<div id="tahminler">
</div>
<div id="notices">
</div>
<div id="tsparticles"></div>
<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>
<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 style="margin-top:auto;text-align:center;">Veri Sorumlusu: Ömer Arda Muratoğlu.<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>
<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>
@ -60,423 +36,5 @@
</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>
function isSameDay(a, b) {
return a.toDateString() == b.toDateString();
}
getPreviousData();
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
date = new Date();
if (localStorage.getItem("latest_visit") === null) {
localStorage.setItem("latest_visit", date);
} else {
latest_visit = localStorage.getItem("latest_visit");
if (isSameDay(new Date(latest_visit), date)) {
console.debug("Kullanıcı Son Girişi İle Aynı Günde");
} else {
console.debug("Kullanıcı Farklı Bir Günde Giriş Yaptı, Statlar Sıfırlanıyor");
localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess");
localStorage.removeItem("win");
document.getElementById("tebriks").style.display = "none";
}
localStorage.setItem("latest_visit", date);
}
<?php include __DIR__ . '/src/server.php'; ?>
current_guess = "<?php
if ($_POST['mainInput'] != null) {
echo htmlspecialchars($_POST['mainInput']);
}
?>";
flagSame = 0;
if (localStorage.getItem("latest_guess") != null) {
if (current_guess == localStorage.getItem("latest_guess")) {
console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!! (veya sayfayı yenilemiş/geri gelmiş de olabilirsiniz)")
flagSame = 1;
}
localStorage.setItem("latest_guess", current_guess);
} else {
localStorage.setItem("latest_guess", current_guess);
}
const persons = <?php echo json_encode(getAllPersonNames(), JSON_UNESCAPED_UNICODE) ?>;
if (persons.includes(current_guess) == false) {
flagSame = 1;
}
var gj = JSON.parse('{"Guesses":[], "Values":[]}'); // guess json
if (localStorage.getItem("guesses") != null) {
console.debug("Local Storage Succesfully Get!");
gj = JSON.parse(localStorage.getItem("guesses"));
}
if (current_guess != "" && flagSame == 0) {
gj["Guesses"].push(current_guess);
console.debug("Denenen Kişi: " + current_guess);
gj["Values"].push(<?php if ($_POST['mainInput'] != null) {
$inner_cg = htmlspecialchars($_POST['mainInput']);
echo "'" . json_encode(comparePerson(reversePerson($inner_cg)), JSON_UNESCAPED_UNICODE) . "'";
}
?>);
localStorage.setItem("guesses", JSON.stringify(gj));
}
const criterias = <?php echo json_encode(getAllCriterias(), JSON_UNESCAPED_UNICODE) ?>;
var crit_num = 0;
var true_num = 0;
var innerFlag = true;
if (gj["Guesses"].length > 0) {
point = document.getElementById("tahminler");
const table = document.createElement("table");
const tr = document.createElement("tr");
table.classList.add("guess-table");
tr.classList.add("guess-tr");
table.appendChild(tr);
point.appendChild(table);
for (const key in criterias) {
const th = document.createElement("th");
const th_text = document.createTextNode(criterias[key]);
th.classList.add("guess-th");
th.appendChild(th_text);
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");
tr.classList.add("guess-tr");
table.appendChild(tr);
indata = JSON.parse(gj["Values"][i]);
// console.warn(indata);
for (const key in criterias) {
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");
break;
case 1:
td.classList.add("type1");
break;
case 2:
td.classList.add("type2");
if (innerFlag) true_num++;
break;
case 10:
td.classList.add("type10");
break;
case 12:
td.classList.add("type12");
break;
}
}
td.classList.add("guess-td");
td.appendChild(td_text);
tr.appendChild(td);
}
innerFlag = false;
}
}
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");
if (flagConf) {
callConfetti();
}
}
// console.log(gj);
if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
yepwin();
}
// NOTICES
notices = JSON.parse('<?php echo json_encode(getAllNotices(), JSON_UNESCAPED_UNICODE); ?>');
tmpflag = true;
notic = document.getElementById("notices");
if (notices.length > 1) {
notic.style.marginTop = "auto";
document.getElementById("sorumli").style.marginTop = "1px";
}
notices.forEach(element => {
if (tmpflag == true) {
tmpflag = false;
} else {
innot = document.createElement("p");
innot.classList.add("innot");
innot_text = element;
innot.innerHTML = innot_text;
notic.appendChild(innot);
}
});
</script>
<script>
// UPDATES
const updates = <?php echo json_encode(sendDataDate()) ?>;
document.getElementById("latest-data").innerHTML = updates[0];
console.info("Günün Kişisi, Son Güncelleme Zamanı: " + updates[1]);
/// AUTOCOMPLETE ///
// TODO maybe fuzzy search: https://www.lucaspaganini.com/academy/autocomplete-with-fuzzy-search-and-fuse-js
// https://www.fusejs.io/
function autocomplete(inp, arr) {
/*the autocomplete function takes two arguments,
the text field element and an array of possible autocompleted values:*/
var currentFocus;
/*execute a function when someone writes in the text field:*/
inp.addEventListener("input", function(e) {
var a, b, i, val = this.value;
/*close any already open lists of autocompleted values*/
closeAllLists();
if (!val) {
return false;
}
currentFocus = -1;
/*create a DIV element that will contain the items (values):*/
a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*append the DIV element as a child of the autocomplete container:*/
this.parentNode.appendChild(a);
/*for each item in the array...*/
for (i = 0; i < arr.length; i++) {
/*check if the item starts with the same letters as the text field value:*/
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
/*create a DIV element for each matching element:*/
b = document.createElement("DIV");
/*make the matching letters bold:*/
b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
b.innerHTML += arr[i].substr(val.length);
/*insert a input field that will hold the current array item's value:*/
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
/*execute a function when someone clicks on the item value (DIV element):*/
b.addEventListener("click", function(e) {
/*insert the value for the autocomplete text field:*/
inp.value = this.getElementsByTagName("input")[0].value;
/*close the list of autocompleted values,
(or any other open lists of autocompleted values:*/
closeAllLists();
});
a.appendChild(b);
}
}
});
/*execute a function presses a key on the keyboard:*/
inp.addEventListener("keydown", function(e) {
var x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
if (e.keyCode == 40) {
/*If the arrow DOWN key is pressed,
increase the currentFocus variable:*/
currentFocus++;
/*and and make the current item more visible:*/
addActive(x);
} else if (e.keyCode == 38) { //up
/*If the arrow UP key is pressed,
decrease the currentFocus variable:*/
currentFocus--;
/*and and make the current item more visible:*/
addActive(x);
} else if (e.keyCode == 13) {
/*If the ENTER key is pressed, prevent the form from being submitted,*/
e.preventDefault();
if (currentFocus > -1) {
/*and simulate a click on the "active" item:*/
if (x) x[currentFocus].click();
}
}
});
function addActive(x) {
/*a function to classify an item as "active":*/
if (!x) return false;
/*start by removing the "active" class on all items:*/
removeActive(x);
if (currentFocus >= x.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = (x.length - 1);
/*add class "autocomplete-active":*/
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
/*a function to remove the "active" class from all autocomplete items:*/
for (var i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllLists(elmnt) {
/*close all autocomplete lists in the document,
except the one passed as an argument:*/
var x = document.getElementsByClassName("autocomplete-items");
for (var i = 0; i < x.length; i++) {
if (elmnt != x[i] && elmnt != inp) {
x[i].parentNode.removeChild(x[i]);
}
}
}
/*execute a function when someone clicks in the document:*/
document.addEventListener("click", function(e) {
closeAllLists(e.target);
});
}
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>

View file

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

View file

@ -1,252 +0,0 @@
<?php
use Yosymfony\Toml\Toml;
include __DIR__ . '/todays.php';
include __DIR__ . '/previous.php';
include __DIR__ . '/../config.php';
require __DIR__ . '/../vendor/autoload.php';
$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 "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
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);
}
$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
function getAllPersonNames()
{
$data = parseTOML()["data"];
$arr = array();
foreach ($data as $d) {
array_push($arr, $d["isim_soyisim"]);
}
return $arr;
}
function getAllCriterias()
{
$data = parseTOML()["public"];
return $data["gozukecek_kriterler"];
}
function getAllNotices()
{
$data = parseTOML()["public"];
return $data["kullanici_notlari"];
}
# send data update date and latest person update date
function sendDataDate()
{
# 1: Get data.toml modified time
# 2: Get latest person update, (should ebe TSI 03.00!)
date_default_timezone_set('Europe/Istanbul');
setlocale(LC_ALL, 'tr_TR');
$filename = "data.toml";
if (file_exists(__DIR__ . "/../" . $filename)) {
$arr[0] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/../" . $filename));
}
$filename = "todays.php";
if (file_exists(__DIR__ . "/" . $filename)) {
$arr[1] = date("d/m/Y H:i:s", filemtime(__DIR__ . "/" . $filename));
}
return $arr;
}
# Aliberk Sandıı -> aliberk_sandikci24
function reversePerson($str)
{
$data = parseTOML()["data"];
foreach ($data as $key => $value) {
if ($value["isim_soyisim"] == $str) {
return $key;
}
}
}
# compare a person with todays person, returns equalities (0-red, 1-orange, 2-green, 10-orange(küçük), 12-orange(büyük))
function comparePerson($person)
{
global $TODAYS_PERSON;
$statGuess = getAPersonStats($person);
$statTodays = getAPersonStats($TODAYS_PERSON);
$kriterler = parseTOML()["public"]["kriterler"];
// $RESULT = array_fill(0, count($kriterler), 0);
for ($i = 0; $i < count($kriterler); $i++) {
$curCrit = array_keys($kriterler)[$i];
switch (array_values($kriterler)[$i]) {
case 'comp':
$RESULT[$curCrit] = [compareCOMP($statGuess[$curCrit], $statTodays[$curCrit]), $statGuess[$curCrit]];
break;
case 'arr':
$RESULT[$curCrit] = [compareARR($statGuess[$curCrit], $statTodays[$curCrit], $curCrit), $statGuess[$curCrit]];
break;
default:
$RESULT[$curCrit] = [compareEQ($statGuess[$curCrit], $statTodays[$curCrit]), $statGuess[$curCrit]];
break;
}
}
return $RESULT;
}
# compare 2 data in EQ format
function compareEQ($guess, $todays)
{
if ($guess == $todays) {
return 2;
} else {
return 0;
}
}
# compare 2 data in COMP format
function compareCOMP($guess, $todays)
{
if ($guess == $todays) {
return 2;
} else if ($guess <= $todays) {
return 12;
} else {
return 10;
}
}
# compare 2 data in ARR format
function compareARR($guess, $todays, $krit)
{
$equalNum = 0;
foreach ($guess as $key1 => $value1) {
foreach ($todays as $key2 => $value2) {
if ($value1 == $value2) {
$equalNum++;
}
}
}
if ($equalNum == 0) {
return 0;
} else if ($equalNum == count($todays) && $equalNum == count($guess)) {
return 2;
} else if ($equalNum >= 1) {
return 1;
} else {
return 0;
}
}
# get a person stat, can be used in other functions
function getAPersonStats($person)
{
return parseTOML()["data"][$person];
}
# parse toml
function parseTOML()
{
global $parser;
$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();
}

View file

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