<?php



?>
<!DOCTYPE html>
<head>
<title>まとめたDE!!</title>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<!--[if lt IE 9]>
<script src="//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="shortcut icon" href="">
</head>
<body>
<table border="1">
<?php
require_once("lib/prepare.php");
$length=100;
$stmt = Database::prepare("SELECT * FROM `item` ORDER BY `id` DESC LIMIT ".$length);
$stmt->execute();
$count = $stmt->rowCount();
for ($i = 0; $i < $count; $i++) {
	$stmt->bindColumn("id", $itemId);
	$stmt->bindColumn("title", $itemTitle);
	$stmt->bindColumn("link", $itemLink);
	$stmt->bindColumn("date", $itemDate);
	$stmt->bindColumn("site", $site);
	$stmt->bindColumn("original_link", $orgLink);
	$stmt->bindColumn("img_url", $imgUrl);
	$stmt->fetch();
	$siteTitle = getSiteName($site);

	$img = "&nbsp;";
	$path = "/var/www/virtual/matome/img/resized/".$itemId.".jpg";
	if (file_exists($path)) {
		$img = "<img src=\"img/resized/".$itemId.".jpg\" width=\"100px\">";
	}
	
	echo "<tr><td>".$img."</td><td>".substr($itemDate,5,11)."</td><td><a href=\"function.createData.php?itemId=".$itemId."&siteId=".$site."\" target=\"_blank\">".$itemTitle."</a></td><td>".$siteTitle."</td></tr>";
}

function getSiteName($siteId) {
	static $cache = array();
	if (isset($cache[$siteId])) return $cache[$siteId];
	$stmt2 = Database::prepare("select title from sites where id = :ID");
	$stmt2->bindParam(":ID", $siteId);
	$stmt2->execute();
	if ($stmt2->rowCount() == 1) {
		$stmt2->bindColumn("title", $title);
		$stmt2->fetch();
		$cache[$siteId] = $title;
		return $cache[$siteId];
	}
	$cache[$siteId] = "";
	return $cache[$siteId];
}
?>
</table>
<!-- Place your content here -->
<!-- SCRIPTS -->
<!-- Example: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
</body>
</html>