/htdocs/h/index.php
<?php
set_time_limit(100);
$baseUri = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/') + 1);
if (!isset($_GET['id']) || intval($_GET['id']) < 1)
{
echo '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>seyuseba</title></head><body><h1>seyuseba</h1><input type="text" id="id" /><button onclick="javascript:(function(){var id=document.getElementById(\'id\').value;id=parseInt(id);if(id > 0)location.href=\'?id=\'+id;})();">go</button><br /><br />';
$curDir = dir('.');
while (false !== ($d = $curDir->read()))
{
if ($d != '.' && $d != '..' && is_dir($d) && is_file($d. DIRECTORY_SEPARATOR. 'img.info'))
echo '<a href="'.$baseUri. $d.'/index.html">'.$d.'</a><br />';
}
$curDir->close();
echo '</body></html>';
exit;
}
$id = intval($_GET['id']);
$path = ''. $id;
if (!is_dir($path))
mkdir($path);
$imgInfo = $path. DIRECTORY_SEPARATOR. 'img.info';
if (!is_file($imgInfo))
{
$tempContent = $path. DIRECTORY_SEPARATOR. 'temp.content';
$content = '';
if (is_file($tempContent))
$content = file_get_contents($tempContent);
else
{
$uri = sprintf('http://www.sexyisex.com/thread-%d-1-1.html', $id);
$content = file_get_contents($uri);
file_put_contents($tempContent, $content);
}
//$pat = '/<img.*file="([^\s]*)" onclick="zoom\(this\)"\s/';
$pat = '/<img.*file="([^\s]*)"\s/';
$arr = array();
if (!preg_match_all($pat, $content, $arr))
exit('canot find img!');
$sum = count($arr[1]);
$fileNameNumPat = '%0'.strlen(''.$sum).'d';
$imgInfoArr = array();
for ($i = 1; $i <= $sum; $i++)
{
$fExt = substr($arr[1][$i-1], strrpos($arr[1][$i-1], '.'), 10);
$fName = sprintf($fileNameNumPat, $i). $fExt;
$fPath = $path. DIRECTORY_SEPARATOR. $fName;
if (!is_file($fPath))
{
$fStr = file_get_contents($arr[1][$i-1]);
file_put_contents($fPath, $fStr);
}
$imgInfoArr[] = $fName;
}
file_put_contents($imgInfo, implode(PHP_EOL, $imgInfoArr). PHP_EOL);
$html = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>seyuseba - ';
$html .= $id;
$html .= '</title></head><body>';
$html .= '<h1>'.$id.'</h1><a href="'.$baseUri.'">back</a><br /><br />';
foreach ($imgInfoArr as $i)
$html .= '<img alt="" src="'.$i.'" /><br />';
$html .= '</body></html>';
file_put_contents($path. DIRECTORY_SEPARATOR. 'index.html', $html);
}
header("Location: ". $baseUri. $id. '/index.html');