2022-08-11 06:44:02 +09:00
|
|
|
|
<?php
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$lang = isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'ja';
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['langchange'])) {
|
|
|
|
|
$lang = null !== $_COOKIE['lang'] && $_COOKIE['lang'] == 'en' ? 'ja' : 'en';
|
|
|
|
|
setcookie('lang', $lang);
|
|
|
|
|
unset($_POST['langchange']);
|
|
|
|
|
header('Location: /');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
include('../lang/'.$lang.'.php');
|
2022-08-11 06:44:02 +09:00
|
|
|
|
require_once('../config.php');
|
|
|
|
|
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title = $lang == 'en' ? SITE_NAME_EN : SITE_NAME_JA;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
|
|
|
|
|
function mkstring () {
|
|
|
|
|
$stringchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
|
|
|
|
$newstring = '';
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < 5; $i++) $newstring .= $stringchars[rand(0, strlen($stringchars))];
|
|
|
|
|
foreach ($arr as $k => $v) {
|
|
|
|
|
if ($newstring == $k) return mkstring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $newstring;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// パラメートルがなければ、スキップ。
|
|
|
|
|
if (isset($_POST['sosin'])) {
|
|
|
|
|
$newadd = $_POST['newadd'];
|
|
|
|
|
if (!str_starts_with($newadd, 'http://') && !str_starts_with($newadd, 'https://')) {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_FUSEINA_URL;
|
|
|
|
|
$err = LOC_ERROR_URL_HTTP_HTTPS;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
include_once('../views/404.php');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen($newadd) > 500) {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_FUSEINA_URL;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
$err = 'URLは500文字以内です。';
|
|
|
|
|
include_once('../views/404.php');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = file_get_contents('links.json');
|
|
|
|
|
|
|
|
|
|
$arr = json_decode($data, true);
|
|
|
|
|
foreach ($arr as $k => $v) {
|
|
|
|
|
if ($newadd == $v) {
|
|
|
|
|
if (isset($_POST['api']) && $_POST['api'] == 1) {
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
echo json_encode(['res' => $k]);
|
|
|
|
|
}
|
|
|
|
|
else header('Location: /?newurl='.$k);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newstring = mkstring();
|
|
|
|
|
|
|
|
|
|
$arr[$newstring] = $newadd;
|
|
|
|
|
$newdata = json_encode($arr);
|
|
|
|
|
file_put_contents('links.json', $newdata);
|
|
|
|
|
|
|
|
|
|
if (isset($_POST['api']) && $_POST['api'] == 1) {
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
echo json_encode(['res' => $newstring]);
|
|
|
|
|
}
|
|
|
|
|
else header('Location: /?newurl='.$newstring);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else if (!isset($_GET['url']) && isset($_GET['newurl'])) {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_TANSYUKUZUMI;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
$newurl = $_GET['newurl'];
|
|
|
|
|
include_once('../views/submitted.php');
|
|
|
|
|
}
|
|
|
|
|
else if (isset($_GET['url']) && $_GET['url'] != '') {
|
|
|
|
|
$data = file_get_contents('links.json');
|
|
|
|
|
|
|
|
|
|
foreach (json_decode($data) as $k => $v) {
|
|
|
|
|
// jsonファイルでキーを見つければ、転送されます。なければ、404エラーが出ます。
|
|
|
|
|
if ($_GET['url'] == $k) {
|
|
|
|
|
if (isset($_GET['api']) && $_GET['api'] == 1) {
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
echo json_encode(['res' => $v]);
|
|
|
|
|
}
|
|
|
|
|
else header('Location: '.$v);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_MIKENSYUTU;
|
|
|
|
|
$err = LOC_ERROR_URL_MITUKAREMASEN;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
include_once('../views/404.php');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!isset($_GET['url']) && $_SERVER['REQUEST_URI'] == '/') {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_TOP;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
include_once('../views/index.php');
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-08-25 18:51:17 +09:00
|
|
|
|
$title .= '〜'.LOC_MIKENSYUTU;
|
|
|
|
|
$err = LOC_ERROR_URL_MITUKAREMASEN;
|
2022-08-11 06:44:02 +09:00
|
|
|
|
include_once('../views/404.php');
|
|
|
|
|
}
|
|
|
|
|
?>
|