gaku-ura/hide_php/img.php

141 行
3.6 KiB
PHP

<?php
//直接アクセスしちゃだめ
require $d_root.'/hide_php/conf/c.php';
require $d_root.'/hide_php/conf/bbs.php';
function vi_image_file_type($image_file_type){
$o = array('gif','png','jpeg','jpg','webp','ico');
foreach ($o as $t){
if (empty($t)){
return '';
}
if (stripos($image_file_type, $t) !== false){
return $t;
}
}
}
$bbs_dir = $d_root.'/sqlike/bbs';
//関数
if (isset($_GET['P'])){
$p = s_pass_d(decode_a($_GET['P']));
if ($p == false){
not_found();
} elseif (preg_match('/^[0-9]+\.(gif|jpeg|jpg|png|webp|ico)/', $p) !== 1){
not_found();
}
$file = $bbs_dir.'/file/'.$p;
if (file_exists($file)){
$type = vi_image_file_type($p);
$size = getimagesize($file);
$date = filemtime($file);
if (empty($type)){
not_found();
} else {
if (isset($_GET['imageonly'])){
$imageonly = (bool)$_GET['imageonly'];
} else {
$imageonly = false;
}
if ($imageonly){
header('Content-Type:image/'.$type);
readfile($file);
} else {
//スレッドをかき集める
$fols = scandir($bbs_dir);
foreach ($fols as $b){
if (substr($b, 0, 1) === '.'){
continue;
}
if (preg_match('/^[0-9]+$/', $b) === 1){
$thread_files = scandir($bbs_dir.'/'.$b);
foreach ($thread_files as $thread_file){
if (substr($thread_file, 0, 1) === '.'){
continue;
}
if (preg_match('/^[0-9]+\.txt/', $thread_file) === 1){
$thread_rows = get_rows($bbs_dir.'/'.$b.'/'.$thread_file, 2);
foreach ($thread_rows as $thread_row){
$d = explode("'", $thread_row);
if (strpos($d[5], '{{'.$p.'}}') !== false){
$title = get($bbs_dir.'/'.$b.'/'.$thread_file, 1);
$board = $b;
//非公開板の場合
if ($board < 200){
$board_data = get($bbs_dir.'/boards.txt', $board);
} else {
$board_data = get($bbs_dir.'/user_board/'.$board.'.txt', 1);
}
if (($board_data === false) || empty($board_data)){
not_found();
}
list($board_title, $board_description, $board_content, $board_access_passwd, $board_edit_passwd) = explode("'", $board_data);
if (($board_access_passwd !== '') && (!isset($_SESSION['login:'.$board]) || ($_SESSION['login:'.$board] !== $board_access_passwd))){
header('Location:./login.php?Board='.$board);
exit;
}
if ($b >= 10){
$b = $b.'-';
}
$area = $b.str_replace('.txt', '', $thread_file).'#'.$d[0];
$name = $d[1];
$key = $d[2];
$color = $d[3];
$description = str_replace('<br>', '', preg_replace('/{{[0-9]+\.(gif|jpeg|jpg|png|webp|ico)}}/', '', $d[5]));
if (strpos($description, '\\\\非表示\\\\') !== false){
not_found();
}
break 3;
}
}
}
}
}
}
if (!isset($description)){
$title = '';
$area = '';
$name = '';
$key = '';
$color = '';
$description = '';
}
######html開始
$replace_array = [
'TITLE' => '添付画像:'.mb_substr(preg_replace('/&gt;&gt;[0-9]+/', '', $description), 0, 20).'-',
'DESCRIPTION' => $description,
'IMAGE_URL' => '/img.php?P='.$_GET['P'],
'WIDTH' => $size[0].'px',
'HEIGHT' => $size[1].'px',
'ALT' => mb_substr(preg_replace('/&gt;&gt;[0-9]+/', '', $description), 0, 8),
'IMAGE_INFOMATION' => '<p>'.date('Y年m月d日 H時i分s秒', $date).'更新、'.user_page($name, $key).'さんの投稿</p><p>'.$description.'</p><p>該当スレッド: <a href="/thread.php?Area='.$area.'">'.$title.'</a></p>'];
$f = $d_root.'/sqlike/html/img/view_image.html';
if (file_exists($f)){
$html = file_get_contents($f);
} else {
readfile($file);
exit;
}
foreach ($replace_array as $word => $result){
$html = str_replace('{'.$word.'}', $result, $html);
}
echo $html;
}
}
} else {
not_found();
}
} else {
not_found();
}