Format old PHP files
This commit is contained in:
@@ -1,220 +1,222 @@
|
||||
<?php
|
||||
if($included==true){
|
||||
// boolean readPage(string $page)
|
||||
function readPage($page){//main function
|
||||
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";
|
||||
}else{
|
||||
$realPage="pages/".$lang."/error/404.pg";
|
||||
$log404=fopen("404.log","a+");
|
||||
if(!ereg($page."\n",file_get_contents("404.log"))){
|
||||
fwrite($log404,$page."\n");
|
||||
mail($mainMail,"Stranka nenalezena http://tojnar.cz/krk/lob2011/$page",rplc("Prichozi z: %comefrom%"));
|
||||
}
|
||||
fclose($log404);
|
||||
}
|
||||
}
|
||||
//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
|
||||
|
||||
$fileContent=rplc(file_get_contents($realPage));
|
||||
//echo($fileContent);
|
||||
$fileContent=ereg_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);
|
||||
declare(strict_types=1);
|
||||
|
||||
ereg("<article>(.*)<\/article>",$fileContent,$article);//article body
|
||||
$article=trim($article[1]);
|
||||
if ($included == true) {
|
||||
// boolean readPage(string $page)
|
||||
function readPage($page) {//main function
|
||||
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';
|
||||
} else {
|
||||
$realPage = 'pages/' . $lang . '/error/404.pg';
|
||||
$log404 = fopen('404.log', 'a+');
|
||||
if (!ereg($page . "\n", file_get_contents('404.log'))) {
|
||||
fwrite($log404, $page . "\n");
|
||||
mail($mainMail, "Stranka nenalezena http://tojnar.cz/krk/lob2011/$page", rplc('Prichozi z: %comefrom%'));
|
||||
}
|
||||
fclose($log404);
|
||||
}
|
||||
}
|
||||
//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
|
||||
|
||||
ereg("<title>(.*)<\/title>",$fileContent,$title);//article title
|
||||
$title=trim($title[1]);
|
||||
$fileContent = rplc(file_get_contents($realPage));
|
||||
//echo($fileContent);
|
||||
$fileContent = preg_replace('/<a([^>]*)hs="([1-9][0-9]?)"([^>]*)>/D', '<a\\1onclick="return hs.expand(this,{slideshowGroup:\\2})"\\3>', $fileContent);
|
||||
$sbContent = rplc(sboard_generate($realPage));
|
||||
$fileContent = str_replace('<board>', $sbContent, $fileContent);
|
||||
|
||||
ereg("<date>(.*)<\/date>",$fileContent,$date);//article title
|
||||
$date=trim($date[1]);
|
||||
preg_match("#<article>(.*)<\/article>#D", $fileContent, $article); //article body
|
||||
$article = trim($article[1]);
|
||||
|
||||
ereg("<author>(.*)<\/author>",$fileContent,$author);//article title
|
||||
$author=trim($author[1]);
|
||||
preg_match("#<title>(.*)<\/title>#D", $fileContent, $title); //article title
|
||||
$title = trim($title[1]);
|
||||
|
||||
$languages=array("cs","en","de");
|
||||
preg_match("#<date>(.*)<\/date>#D", $fileContent, $date); //article title
|
||||
$date = trim($date[1]);
|
||||
|
||||
ereg("<alias([^>]*)cs(e?)=\"([^\"]*)\"([^>]*)>",$fileContent,$cs);//article czech version link
|
||||
$aliases["cs"]=($cs[2]=='e'?'*':'').trim($cs[3]);
|
||||
preg_match("#<author>(.*)<\/author>#D", $fileContent, $author); //article title
|
||||
$author = trim($author[1]);
|
||||
|
||||
ereg("<alias([^>]*)en(e?)=\"([^\"]*)\"([^>]*)>",$fileContent,$en);//article english version link
|
||||
$aliases["en"]=($en[2]=='e'?'*':'').trim($en[3]);
|
||||
$languages = ['cs', 'en', 'de'];
|
||||
|
||||
ereg("<alias([^>]*)de(e?)=\"([^\"]*)\"([^>]*)>",$fileContent,$de);//article german version link
|
||||
$aliases["de"]=($de[2]=='e'?'*':'').trim($de[3]);
|
||||
preg_match('/<alias([^>]*)cs(e?)="([^"]*)"([^>]*)>/D', $fileContent, $cs); //article czech version link
|
||||
$aliases['cs'] = ($cs[2] == 'e' ? '*' : '') . trim($cs[3]);
|
||||
|
||||
ereg("<menu url=\"([^\"]*)\">",$fileContent,$menuUrl);//article menu url
|
||||
$menuUrl=trim($menuUrl[1]);
|
||||
foreach($languages as $language){//language box generator
|
||||
if(mb_substr($aliases[$language], 0, 1)=='*'){
|
||||
$langPanel.=rplc("<a href=\"".mb_substr($aliases[$language], 1)."\"><img src=\"%root%/gpx/".$language."flag.png\" alt=\"".$language."\"></a>");
|
||||
}else{
|
||||
if(!empty($aliases[$language]) && file_exists("pages/".$language."/".$aliases[$language].".pg")){
|
||||
$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
|
||||
preg_match('/<alias([^>]*)en(e?)="([^"]*)"([^>]*)>/D', $fileContent, $en); //article english version link
|
||||
$aliases['en'] = ($en[2] == 'e' ? '*' : '') . trim($en[3]);
|
||||
|
||||
#$author=$realPageType==1?"":rplc($author);
|
||||
/*if($realPageType==0){
|
||||
if(empty($date)){
|
||||
$date=date(rplc("%dateFormat%"),filemtime($realPage));
|
||||
}
|
||||
}
|
||||
*/
|
||||
if(empty($menuUrl) OR !file_exists($menuUrl)){
|
||||
$menuUrl="main";
|
||||
}
|
||||
$menu=rplc(file_get_contents("pages/".$lang."/".$menuUrl.".mn"));
|
||||
$article=rplc($article);
|
||||
if(ereg("<goto url=\"([^\"]+)\">",$fileContent,$gotoUrl)){
|
||||
if($page==$gotoUrl[1]){
|
||||
$logrecursive=fopen("syntax.log","a+");
|
||||
if(!ereg($realPage."\n",file_get_contents("recursive.log"))){
|
||||
fwrite($logrecursive,$realPage."\n");
|
||||
mail($mainMail,"Presmerovaci smycka http://tojnar.cz/krk/lob2011/$realPage","Stranka se presmerovava sama na sebe");
|
||||
}
|
||||
fclose($logrecursive);
|
||||
readPage("error/recursive");
|
||||
}else{
|
||||
readPage($gotoUrl[1]);
|
||||
}
|
||||
}
|
||||
preg_match('/<alias([^>]*)de(e?)="([^"]*)"([^>]*)>/D', $fileContent, $de); //article german version link
|
||||
$aliases['de'] = ($de[2] == 'e' ? '*' : '') . trim($de[3]);
|
||||
|
||||
preg_match('/<menu url="([^"]*)">/D', $fileContent, $menuUrl); //article menu url
|
||||
$menuUrl = trim($menuUrl[1]);
|
||||
foreach ($languages as $language) {//language box generator
|
||||
if (mb_substr($aliases[$language], 0, 1) == '*') {
|
||||
$langPanel .= rplc('<a href="' . mb_substr($aliases[$language], 1) . '"><img src="%root%/gpx/' . $language . 'flag.png" alt="' . $language . '"></a>');
|
||||
} else {
|
||||
if (!empty($aliases[$language]) && file_exists('pages/' . $language . '/' . $aliases[$language] . '.pg')) {
|
||||
$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
|
||||
|
||||
//$author=$realPageType==1?"":rplc($author);
|
||||
/*if($realPageType==0){
|
||||
if(empty($date)){
|
||||
$date=date(rplc("%dateFormat%"),filemtime($realPage));
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (empty($menuUrl) || !file_exists($menuUrl)) {
|
||||
$menuUrl = 'main';
|
||||
}
|
||||
$menu = rplc(file_get_contents('pages/' . $lang . '/' . $menuUrl . '.mn'));
|
||||
$article = rplc($article);
|
||||
if (preg_match('/<goto url="([^"]+)">/D', $fileContent, $gotoUrl)) {
|
||||
if ($page == $gotoUrl[1]) {
|
||||
$logrecursive = fopen('syntax.log', 'a+');
|
||||
if (!ereg($realPage . "\n", file_get_contents('recursive.log'))) {
|
||||
fwrite($logrecursive, $realPage . "\n");
|
||||
mail($mainMail, "Presmerovaci smycka http://tojnar.cz/krk/lob2011/$realPage", 'Stranka se presmerovava sama na sebe');
|
||||
}
|
||||
fclose($logrecursive);
|
||||
readPage('error/recursive');
|
||||
} else {
|
||||
readPage($gotoUrl[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strpos($fileContent,"<eu>")!=false){
|
||||
$eu=true;
|
||||
}else{
|
||||
$eu=false;
|
||||
}
|
||||
if (strpos($fileContent, '<eu>') != false) {
|
||||
$eu = true;
|
||||
} else {
|
||||
$eu = false;
|
||||
}
|
||||
|
||||
if (empty($title) && empty($article)) {
|
||||
$logsyntax = fopen('syntax.log', 'a+');
|
||||
if (!ereg($realPage . "\n", file_get_contents('syntax.log'))) {
|
||||
fwrite($logsyntax, $realPage . "\n");
|
||||
mail($mainMail, "Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage", 'Nerozpoznan titulek a clanek');
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage('error/syntax');
|
||||
|
||||
return false;
|
||||
} elseif (empty($title)) {
|
||||
$logsyntax = fopen('syntax.log', 'a+');
|
||||
if (!ereg($realPage . "\n", file_get_contents('syntax.log'))) {
|
||||
fwrite($logsyntax, $realPage . "\n");
|
||||
mail($mainMail, "Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage", 'Nerozpoznan titulek');
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage('error/syntax');
|
||||
|
||||
if(empty($title) AND empty($article)){
|
||||
$logsyntax=fopen("syntax.log","a+");
|
||||
if(!ereg($realPage."\n",file_get_contents("syntax.log"))){
|
||||
fwrite($logsyntax,$realPage."\n");
|
||||
mail($mainMail,"Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage","Nerozpoznan titulek a clanek");
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage("error/syntax");
|
||||
return false;
|
||||
}elseif(empty($title)){
|
||||
$logsyntax=fopen("syntax.log","a+");
|
||||
if(!ereg($realPage."\n",file_get_contents("syntax.log"))){
|
||||
fwrite($logsyntax,$realPage."\n");
|
||||
mail($mainMail,"Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage","Nerozpoznan titulek");
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage("error/syntax");
|
||||
return false;
|
||||
}elseif(empty($article)){
|
||||
$logsyntax=fopen("syntax.log","a+");
|
||||
if(!ereg($realPage."\n",file_get_contents("syntax.log"))){
|
||||
fwrite($logsyntax,$realPage."\n");
|
||||
mail($mainMail,"Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage","Nerozpoznan clanek");
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage("error/syntax");
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} elseif (empty($article)) {
|
||||
$logsyntax = fopen('syntax.log', 'a+');
|
||||
if (!ereg($realPage . "\n", file_get_contents('syntax.log'))) {
|
||||
fwrite($logsyntax, $realPage . "\n");
|
||||
mail($mainMail, "Chyba syntaxe http://tojnar.cz/krk/lob2011/$realPage", 'Nerozpoznan clanek');
|
||||
}
|
||||
fclose($logsyntax);
|
||||
readPage('error/syntax');
|
||||
|
||||
// string|null author(string $author)
|
||||
function author($author){
|
||||
global $realPageType;
|
||||
if($realPageType==0){
|
||||
if(empty($author)){
|
||||
return rplc("%unknownAuthor%");
|
||||
}else{
|
||||
return $author;
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// string|null toDate(string $date)
|
||||
function toDate($dateStr){
|
||||
if(!empty($dateStr)){
|
||||
$dateStr=explode(" ",$dateStr);
|
||||
$dateStr=$dateStr[0];
|
||||
$dateStr=explode("-",$dateStr);
|
||||
$year=$dateStr[0];
|
||||
$month=ltrim($dateStr[1],"0");
|
||||
$day=ltrim($dateStr[2],"0");
|
||||
return str_replace(array("%y%","%m%","%d%"),array($year,$month,$day),rplc("%date%"));
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// string|null author(string $author)
|
||||
function author($author) {
|
||||
global $realPageType;
|
||||
if ($realPageType == 0) {
|
||||
if (empty($author)) {
|
||||
return rplc('%unknownAuthor%');
|
||||
} else {
|
||||
return $author;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isReleased($dateStr){
|
||||
$dateStr=explode(" ",$dateStr);
|
||||
$dateStr=$dateStr[0];
|
||||
$dateStr=explode("-",$dateStr);
|
||||
$year=$dateStr[0];
|
||||
$month=ltrim($dateStr[1],"0");
|
||||
$day=ltrim($dateStr[2],"0");
|
||||
$time=explode(" ",$dateStr);
|
||||
$time=explode(":",$time[1]);
|
||||
$hour=$time[0];
|
||||
$minute=$time[1];
|
||||
if(date("Y")>=$year){
|
||||
if(date("m")>=$month){
|
||||
if(date("d")>=$day){
|
||||
if(date("H")>=$hour){
|
||||
if(date("i")>=$minute){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// string|null toDate(string $date)
|
||||
function toDate($dateStr) {
|
||||
if (!empty($dateStr)) {
|
||||
$dateStr = explode(' ', $dateStr);
|
||||
$dateStr = $dateStr[0];
|
||||
$dateStr = explode('-', $dateStr);
|
||||
$year = $dateStr[0];
|
||||
$month = ltrim($dateStr[1], '0');
|
||||
$day = ltrim($dateStr[2], '0');
|
||||
|
||||
// string|null toTime(string $date)
|
||||
function toTime($dateStr){
|
||||
if(!empty($dateStr)){
|
||||
$time=explode(" ",$dateStr);
|
||||
$time=$time[1];
|
||||
return $time;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return str_replace(['%y%', '%m%', '%d%'], [$year, $month, $day], rplc('%date%'));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
header("HTTP/1.0 403 Forbidden");
|
||||
header("Location: /en/error/403");
|
||||
function isReleased($dateStr) {
|
||||
$dateStr = explode(' ', $dateStr);
|
||||
$dateStr = $dateStr[0];
|
||||
$dateStr = explode('-', $dateStr);
|
||||
$year = $dateStr[0];
|
||||
$month = ltrim($dateStr[1], '0');
|
||||
$day = ltrim($dateStr[2], '0');
|
||||
$time = explode(' ', $dateStr);
|
||||
$time = explode(':', $time[1]);
|
||||
$hour = $time[0];
|
||||
$minute = $time[1];
|
||||
if (date('Y') >= $year) {
|
||||
if (date('m') >= $month) {
|
||||
if (date('d') >= $day) {
|
||||
if (date('H') >= $hour) {
|
||||
if (date('i') >= $minute) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// string|null toTime(string $date)
|
||||
function toTime($dateStr) {
|
||||
if (!empty($dateStr)) {
|
||||
$time = explode(' ', $dateStr);
|
||||
$time = $time[1];
|
||||
|
||||
return $time;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
header('Location: /en/error/403');
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user