private function getFileInformation($hash)
{
$shrinkWrap = $this->shrinkWrapper;
$results = $shrinkWrap->query("SELECT SQL_NO_CACHE * FROM `file_info` WHERE `torrent_hash` = '{$hash}'");
if (empty($results)) {
$torrentFile = "C:/xampp/htdocs/apps/strike/torrents/api/download/" . $hash . ".torrent";
$torrentTitle = $value["torrent_title"];
if (!file_exists($torrentFile)) {
$remoteTorrent = "http://torcache.net/torrent/{$hash}.torrent";
$file_headers = @get_headers($file);
if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
} else {
$this->downloadFile($remoteTorrent, "C:/xampp/htdocs/apps/strike/torrents/api/download/" . $hash . ".torrent");
}
}
$torrent = new Torrent($torrentFile);
$file_names = array_keys($torrent->content());
$file_lengths = array_values($torrent->content());
$fileNameRecord = "";
$fileLengthRecord = "";
foreach ($file_names as &$value) {
$fileNameRecord .= strlen($fileNameRecord) == 0 ? trim($value) : ", " . trim($value);
}
foreach ($file_lengths as &$value) {
$fileLengthRecord .= strlen($fileLengthRecord) == 0 ? trim($value) : ", " . trim($value);
}
if (strpos($fileNameRecord, 'xampp') !== false) {
$fileNameRecord = "Error";
}
$lengthArray = json_decode('[' . $fileLengthRecord . ']', true);
$nameArray = explode(',', $fileNameRecord);
$fileData = array(file_names => $nameArray, file_lengths => $lengthArray);
$fileNameRecord = $this->shrinkWrapper->escape($fileNameRecord);
$fileLengthRecord = $this->shrinkWrapper->escape($fileLengthRecord);
$insertFileNames = $shrinkWrap->query("REPLACE into file_info (torrent_hash, file_names, file_sizes) values(\"{$hash}\", \"{$fileNameRecord}\", \"{$fileLengthRecord}\")");
return $fileData;
} else {
$fileLengthRecord = $results[0]["file_sizes"];
$fileNameRecord = $results[0]["file_names"];
if (strpos($fileNameRecord, 'xampp') !== false) {
$fileNameRecord = "Error";
}
$lengthArray = json_decode('[' . $fileLengthRecord . ']', true);
$nameArray = explode(',', $fileNameRecord);
$fileData = array(file_names => $nameArray, file_lengths => $lengthArray);
return $fileData;
}
}