generateImageResource($query, $width, $height, false, $radius)); } echo file_get_contents($filename); } else { $icon = new Icon(); echo $icon->generateImageResource($query, $width, $height, false, $radius); } break; case 'snap': // Connect database $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); // Init request $crc32ip = crc32(!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); // Get snap details from DB if ($hostPageSnap = $db->getHostPageSnap(!empty($_GET['hps']) ? (int) $_GET['hps'] : 0)) { // Get snap file $snapStorageIndex = 0; foreach (json_decode(SNAP_STORAGE) as $name => $storages) { foreach ($storages as $storage) { $snapStorageIndex++; // Generate storage id $crc32name = crc32(sprintf('%s.%s', $name, $snapStorageIndex)); switch ($name) { case 'localhost': if ($hostPageSnapStorage = $db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) { // Check request quota //if () // Get file $snapFile = 'hp/' . chunk_split($hostPageSnap->hostPageId, 1, '/') . $hostPageSnap->timeAdded . '.zip'; // Download local snap in higher priority if possible if (file_exists($storage->directory . $snapFile) && is_readable($storage->directory . $snapFile)) { // Register snap download $db->addHostPageSnapDownload($hostPageSnapStorage->hostPageSnapStorageId, $crc32ip, time()); // Return snap file header('Content-Type: application/zip'); header(sprintf('Content-Length: %s', $snapSize)); header(sprintf('Content-Disposition: filename="snap.%s.%s.%s.zip"', $hostPageSnap->hostPageSnapId, $hostPageSnap->hostPageId, $hostPageSnap->timeAdded)); readfile($storage->directory . $snapFile); exit; } } break; case 'ftp': if ($hostPageSnapStorage = $db->getHostPageSnapStorageByCRC32Name($hostPageSnap->hostPageSnapId, $crc32name)) { $ftp = new Ftp(); if ($ftp->connect($storage->host, $storage->port, $storage->username, $storage->password, $storage->directory, $storage->timeout, $storage->passive)) { // Register snap download $db->addHostPageSnapDownload($hostPageSnapStorage->hostPageSnapStorageId, $crc32ip, time()); // Return snap file header('Content-Type: application/zip'); header(sprintf('Content-Length: %s', $snapSize)); header(sprintf('Content-Disposition: filename="snap.%s.%s.%s.zip"', $hostPageSnap->hostPageSnapId, $hostPageSnap->hostPageId, $hostPageSnap->timeAdded)); $ftp->get($snapFile, 'php://output'); $ftp->close(); exit; } } break; } } } } header('HTTP/1.0 404 Not Found'); echo _('404 Snap not found'); break; default: header('HTTP/1.0 404 Not Found'); echo _('404'); }