[add] fix manual generation and preview

This commit is contained in:
Knah Tsaeb 2013-10-14 12:30:24 +02:00
parent 1ef67023fe
commit 54760730bf

View file

@ -82,7 +82,9 @@ function manualGen($hash, $log) {
$line = explode(' --- ', $line);
$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1]));
file_put_contents('cache/tmp/manual.txt', $line[1]);
exec('bin/thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
chdir('bin/');
exec('bash thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
chdir('../');
if ((int)$result[0] === 1) {
$res['success'] = 1;
$res['filePath'] = pathForFile($line[4], $hash).'.png';
@ -108,10 +110,13 @@ function tryRootDomain($hash, $log) {
$parts = parse_url($line[1]);
$url = $parts['scheme'].'://'.trim($parts['host']);
file_put_contents('cache/tmp/manual.txt', $url);
exec('bin/thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
chdir('bin/');
exec('bash thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
chdir('../');
if ((int)$result[0] === 1) {
$res['success'] = 1;
$res['filePath'] = pathForFile($line[4], $hash).'.png';
$res['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents($res['filePath']));
return $res;
}
}
@ -155,7 +160,7 @@ echo '<div class="hMenu">
</ul>
</div>
<div id="log">';
if ($ui['ac'] === 'delete') {
if (isset($ui['ac']) && $ui['ac'] === 'delete') {
if (isset($ui['deleteUrl']) && testValidUrl($ui['deleteUrl']) !== true) {
unset($ui['deleteUrl']);
echo '<div>Not a valid url.</div>';
@ -197,7 +202,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') {
$nbThumb = 0;
$nbThumb = count($logs['genTime']);
echo 'Total request : ', $nbThumb, '</br>';
echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))</br>';
echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))</br>';
} else {
echo 'No result';
}
@ -211,6 +216,7 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' ||
}
if (isset($ui['cache']) && (int)$ui['cache'] === 1) {
$success['filePath'] = pathForFile($ui['s'], $ui['hash']).'.png';
$success['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents($success['filePath']));
if (!file_exists($success['filePath'])) {
$success['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents('bin/error.png'));
}