2022-01-14 10:22:22 +01:00
|
|
|
<?php
|
|
|
|
|
|
2022-01-14 10:48:52 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
function isHttps(): bool {
|
|
|
|
|
// https://www.designcise.com/web/tutorial/how-to-check-for-https-request-in-php
|
|
|
|
|
$isHttps = $_SERVER['HTTPS'] ?? $_SERVER['REQUEST_SCHEME'] ?? $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? null;
|
|
|
|
|
|
|
|
|
|
return $isHttps && (strcasecmp('on', $isHttps) === 0 || strcasecmp('https', $isHttps) === 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function readPage(string $page): bool {
|
|
|
|
|
//main function
|
|
|
|
|
$aliases = [];
|
|
|
|
|
global $lang,$realPageType,$menuUrl,$article,$title,$author,$date,$time,$menu,$mainMail,$langPanel,$notreleased, $eu;
|
|
|
|
|
if (empty($page)) {//page specification
|
|
|
|
|
$realPage = 'pages/' . $lang . '/main.pg';
|
|
|
|
|
} else {
|
|
|
|
|
if (file_exists('pages/' . $lang . '/' . $page . '.pg')) {
|
|
|
|
|
$realPage = 'pages/' . $lang . '/' . $page . '.pg';
|
2022-01-14 10:48:52 +01:00
|
|
|
} else {
|
2022-01-14 11:52:46 +01:00
|
|
|
$realPage = 'pages/' . $lang . '/error/404.pg';
|
|
|
|
|
$log404 = fopen('404.log', 'a+');
|
|
|
|
|
if (!preg_match('(' . preg_quote($page) . '\n)', file_get_contents('404.log'))) {
|
|
|
|
|
fwrite($log404, $page . "\n");
|
2022-01-19 00:57:24 +01:00
|
|
|
mail($mainMail, "Stranka nenalezena https://krk.tojnar.cz/lob2011/$page", rplc('Prichozi z: %comefrom%'));
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
fclose($log404);
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
|
|
|
|
//end of page specification
|
|
|
|
|
$errPageStart = 'pages/' . $lang . '/error/';
|
|
|
|
|
if (substr($realPage, 0, strlen($errPageStart)) == $errPageStart) {//page type setting
|
|
|
|
|
$realPageType = 2;
|
|
|
|
|
} elseif ($realPage == 'pages/' . $lang . '/main.pg') {
|
|
|
|
|
$realPageType = 1;
|
|
|
|
|
} else {
|
|
|
|
|
$realPageType = 0;
|
|
|
|
|
}
|
|
|
|
|
//end of page type setting
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
$fileContent = rplc(file_get_contents($realPage));
|
|
|
|
|
//echo($fileContent);
|
|
|
|
|
$fileContent = preg_replace('(<a([^>]*)hs="([1-9][0-9]?)"([^>]*)>)', '<a\\1onclick="return hs.expand(this,{slideshowGroup:\\2})"\\3>', $fileContent);
|
|
|
|
|
$sbContent = rplc(sboard_generate($realPage));
|
|
|
|
|
$fileContent = str_replace('<board>', $sbContent, $fileContent);
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<article>(.*)</article>)s', $fileContent, $article)) {
|
|
|
|
|
//article body
|
2022-01-14 10:48:52 +01:00
|
|
|
$article = trim($article[1]);
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
$article = '';
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<title>(.*)</title>)s', $fileContent, $title)) {
|
|
|
|
|
//article title
|
2022-01-14 10:48:52 +01:00
|
|
|
$title = trim($title[1]);
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
$title = '';
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<date>(.*)</date>)s', $fileContent, $date)) {
|
|
|
|
|
//article release time
|
2022-01-14 10:48:52 +01:00
|
|
|
$date = trim($date[1]);
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
$date = null;
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<author>(.*)</author>)s', $fileContent, $author)) {
|
|
|
|
|
//article author
|
2022-01-14 10:48:52 +01:00
|
|
|
$author = trim($author[1]);
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
$author = null;
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
$languages = ['cs', 'en', 'de'];
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<alias([^>]*)cs(e?)="([^"]*)"([^>]*)>)', $fileContent, $cs)) {
|
|
|
|
|
//article czech version link
|
2022-01-14 10:48:52 +01:00
|
|
|
$aliases['cs'] = ($cs[2] == 'e' ? '*' : '') . trim($cs[3]);
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<alias([^>]*)en(e?)="([^"]*)"([^>]*)>)', $fileContent, $en)) {
|
|
|
|
|
//article english version link
|
2022-01-14 10:48:52 +01:00
|
|
|
$aliases['en'] = ($en[2] == 'e' ? '*' : '') . trim($en[3]);
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<alias([^>]*)de(e?)="([^"]*)"([^>]*)>)', $fileContent, $de)) {
|
|
|
|
|
//article german version link
|
2022-01-14 10:48:52 +01:00
|
|
|
$aliases['de'] = ($de[2] == 'e' ? '*' : '') . trim($de[3]);
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (preg_match('(<menu url="([^"]*)">)', $fileContent, $menuUrl)) {
|
|
|
|
|
//article menu url
|
2022-01-14 10:48:52 +01:00
|
|
|
$menuUrl = trim($menuUrl[1]);
|
2022-01-14 11:52:46 +01:00
|
|
|
//language box generator
|
|
|
|
|
foreach ($languages as $language) {
|
|
|
|
|
if (isset($aliases[$language]) && str_starts_with($aliases[$language], '*')) {
|
2022-01-14 10:48:52 +01:00
|
|
|
$langPanel .= rplc('<a href="' . mb_substr($aliases[$language], 1) . '"><img src="%root%/gpx/' . $language . 'flag.png" alt="' . $language . '"></a>');
|
|
|
|
|
} else {
|
2022-01-14 11:52:46 +01:00
|
|
|
if (isset($aliases[$language]) && file_exists('pages/' . $language . '/' . $aliases[$language] . '.pg')) {
|
2022-01-14 10:48:52 +01:00
|
|
|
$langPanel .= rplc('<a href="%root%/' . $language . '/' . ($aliases[$language] == 'main' ? '' : $aliases[$language]) . '"><img src="%root%/gpx/' . $language . 'flag.png" alt="' . $language . '"></a>');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//end of language box generator
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
$menuUrl = null;
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
$author = $realPageType == 1 || $author === null ? '' : rplc($author);
|
|
|
|
|
/*if($realPageType==0){
|
|
|
|
|
if(empty($date)){
|
|
|
|
|
$date=date(rplc("%dateFormat%"),filemtime($realPage));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
if ($menuUrl === null || !file_exists($menuUrl)) {
|
|
|
|
|
$menuUrl = 'main';
|
|
|
|
|
}
|
|
|
|
|
$menu = rplc(file_get_contents('pages/' . $lang . '/' . $menuUrl . '.mn'));
|
|
|
|
|
$article = rplc($article);
|
|
|
|
|
if (preg_match('(<goto url="([^"]+)">)', $fileContent, $gotoUrl)) {
|
|
|
|
|
if ($page == $gotoUrl[1]) {
|
|
|
|
|
$logrecursive = fopen('syntax.log', 'a+');
|
|
|
|
|
if (!preg_match('(' . preg_quote($realPage) . '\n)', file_get_contents('recursive.log'))) {
|
|
|
|
|
fwrite($logrecursive, $realPage . "\n");
|
2022-01-19 00:57:24 +01:00
|
|
|
mail($mainMail, "Presmerovaci smycka https://krk.tojnar.cz/lob2011/$realPage", 'Stranka se presmerovava sama na sebe');
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
fclose($logrecursive);
|
|
|
|
|
readPage('error/recursive');
|
2022-01-14 10:48:52 +01:00
|
|
|
} else {
|
2022-01-14 11:52:46 +01:00
|
|
|
readPage($gotoUrl[1]);
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (strpos($fileContent, '<eu>') != false) {
|
|
|
|
|
$eu = true;
|
|
|
|
|
} else {
|
|
|
|
|
$eu = false;
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
if (empty($title) && empty($article)) {
|
|
|
|
|
$logsyntax = fopen('syntax.log', 'a+');
|
|
|
|
|
if (!preg_match('(' . preg_quote($realPage) . '\n)', file_get_contents('syntax.log'))) {
|
|
|
|
|
fwrite($logsyntax, $realPage . "\n");
|
2022-01-19 00:57:24 +01:00
|
|
|
mail($mainMail, "Chyba syntaxe https://krk.tojnar.cz/lob2011/$realPage", 'Nerozpoznan titulek a clanek');
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
fclose($logsyntax);
|
|
|
|
|
readPage('error/syntax');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} elseif (empty($title)) {
|
|
|
|
|
$logsyntax = fopen('syntax.log', 'a+');
|
|
|
|
|
if (!preg_match('(' . preg_quote($realPage) . '\n)', file_get_contents('syntax.log'))) {
|
|
|
|
|
fwrite($logsyntax, $realPage . "\n");
|
2022-01-19 00:57:24 +01:00
|
|
|
mail($mainMail, "Chyba syntaxe https://krk.tojnar.cz/lob2011/$realPage", 'Nerozpoznan titulek');
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
|
|
|
|
fclose($logsyntax);
|
|
|
|
|
readPage('error/syntax');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
} elseif (empty($article)) {
|
|
|
|
|
$logsyntax = fopen('syntax.log', 'a+');
|
|
|
|
|
if (!preg_match('(' . preg_quote($realPage) . '\n)', file_get_contents('syntax.log'))) {
|
|
|
|
|
fwrite($logsyntax, $realPage . "\n");
|
2022-01-19 00:57:24 +01:00
|
|
|
mail($mainMail, "Chyba syntaxe https://krk.tojnar.cz/lob2011/$realPage", 'Nerozpoznan clanek');
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
|
|
|
|
fclose($logsyntax);
|
|
|
|
|
readPage('error/syntax');
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
function author(string $author): ?string {
|
|
|
|
|
global $realPageType;
|
|
|
|
|
if ($realPageType == 0) {
|
|
|
|
|
if (empty($author)) {
|
|
|
|
|
return rplc('%unknownAuthor%');
|
2022-01-14 10:48:52 +01:00
|
|
|
} else {
|
2022-01-14 11:52:46 +01:00
|
|
|
return $author;
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
return null;
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
function toDate(?string $dateStr): ?string {
|
|
|
|
|
if (!empty($dateStr)) {
|
2022-01-14 10:48:52 +01:00
|
|
|
$dateStr = explode(' ', $dateStr);
|
|
|
|
|
$dateStr = $dateStr[0];
|
|
|
|
|
$dateStr = explode('-', $dateStr);
|
|
|
|
|
$year = $dateStr[0];
|
|
|
|
|
$month = ltrim($dateStr[1], '0');
|
|
|
|
|
$day = ltrim($dateStr[2], '0');
|
2022-01-14 11:52:46 +01:00
|
|
|
|
|
|
|
|
return str_replace(['%y%', '%m%', '%d%'], [$year, $month, $day], rplc('%date%'));
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isReleased(?string $datetimeStr): bool {
|
|
|
|
|
if ($datetimeStr === null || $datetimeStr === '') {
|
|
|
|
|
// Empty date = release immediately
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$datetime = explode(' ', $datetimeStr);
|
|
|
|
|
if (!isset($datetime[1])) {
|
|
|
|
|
$datetime[1] = '00:00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[$year, $month, $day] = explode('-', $datetime[0]);
|
|
|
|
|
$month = ltrim($month, '0');
|
|
|
|
|
$day = ltrim($day, '0');
|
|
|
|
|
[$hour, $minute] = explode(':', $datetime[1]);
|
|
|
|
|
if (date('Y') >= $year) {
|
|
|
|
|
if (date('m') >= $month) {
|
|
|
|
|
if (date('d') >= $day) {
|
|
|
|
|
if (date('H') >= $hour) {
|
|
|
|
|
if (date('i') >= $minute) {
|
|
|
|
|
return true;
|
2022-01-14 10:48:52 +01:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
} else {
|
|
|
|
|
return false;
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 11:52:46 +01:00
|
|
|
}
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
function toTime(?string $dateStr): ?string {
|
|
|
|
|
if (!empty($dateStr)) {
|
|
|
|
|
$time = explode(' ', $dateStr);
|
2022-01-14 10:48:52 +01:00
|
|
|
|
2022-01-14 11:52:46 +01:00
|
|
|
return $time[1] ?? null;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
2022-01-14 10:48:52 +01:00
|
|
|
}
|
2022-01-14 10:22:22 +01:00
|
|
|
}
|