diff --git a/bin/error_fav.png b/bin/error_fav.png new file mode 100644 index 0000000..069194d Binary files /dev/null and b/bin/error_fav.png differ diff --git a/inc/admin.php b/inc/admin.php index 34a261b..ecb060d 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -76,6 +76,32 @@ function parseFailLog($log) return $res; } +function parseFaviconLog($log) +{ + if (empty($log) || ($log !== 'favicon')) { + die('Are you sure about this.'); + } + $res = array(); + $list = glob('cache/logs/' . $log . '/*.json'); + if (!empty($list)) { + foreach ($list as $value) { + $res[] = json_decode(file_get_contents($value), true); + } + } + return $res; +} + +function getInfoLog($hash) +{ + $file = 'cache/logs/favicon/' . $hash . '.json'; + if (file_exists($file)) { + $res = json_decode(file_get_contents($file), true); + } else { + $res = array(); + } + return $res; +} + function manualGen($hash, $log) { $line = file_get_contents('cache/logs/' . $log . '/' . $hash . '.log'); @@ -135,9 +161,13 @@ function tryRootDomain($hash, $log) } } -function keepThisThumb($hash, $log) +function keepThisThumb($hash, $log, $favicon = false) { - unlink('cache/logs/' . $log . '/' . $hash . '.log'); + if ($favicon === true) { + unlink('cache/logs/' . $log . '/' . $hash . '.json'); + } else { + unlink('cache/logs/' . $log . '/' . $hash . '.log'); + } } function tryWithCurl($hash, $log) @@ -147,7 +177,7 @@ function tryWithCurl($hash, $log) $line = explode(' --- ', $line); //$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1])); $line[1] = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $line[1]); - $ch = curl_init(); + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $line[1]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @@ -170,14 +200,14 @@ function tryWithCurl($hash, $log) exec('bash thumb_server.sh ../cache/tmp/' . $hash . '.html ' . escapeshellarg($line[2]) . ' ' . escapeshellarg($line[3]) . ' ' . escapeshellarg($line[4]) . ' trc 1 noErrorLog', $result); chdir('../'); unlink('cache/tmp/' . $hash . '.html'); - if ((int) $result[0] == 1) { + if (file_exists(pathForFile($line[4], $hash) . '.png')) { $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; } else { $res['error'] = 1; - $res['msg'] = 'Error with curl'.n_print($result); + $res['msg'] = 'Error with curl' . n_print($result); return $res; } } @@ -190,7 +220,7 @@ function tryWithOpenGraph($hash, $log) $line = explode(' --- ', $line); $url = $line[1]; $startPath = ''; - $url = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $url); + $url = iconv(mb_detect_encoding($line[1], mb_detect_order(), true), "UTF-8", $url); $info = Embed::create($url); $ext = testIfImg($info->image); @@ -210,6 +240,7 @@ function tryWithOpenGraph($hash, $log) } else { $res['error'] = 1; $res['msg'] = 'Error with OpenGraph data'; + $res['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents('bin/error.png')); return $res; } @@ -310,7 +341,13 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || if (isset($ui['cache']) && (int) $ui['cache'] === 1) { $response['success'] = 1; $response['filePath'] = pathForFile($ui['s'], $ui['hash']) . '.png'; - $response['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents($response['filePath'])); + if(file_exists($response['filePath'])){ + $file = file_get_contents($response['filePath']); + } else { + $file = file_get_contents('bin/error.png'); + } + + $response['base64'] = 'data:image/png;base64,' . base64_encode($file); if (!file_exists($response['filePath'])) { $response['base64'] = 'data:image/png;base64,' . base64_encode(file_get_contents('bin/error.png')); } @@ -339,29 +376,30 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || echo 'No result'; } } + echo ''; if (!empty($response) && !empty($response['success']) && $response['success'] === 1) { echo '
'; - echo ''; + echo ''; echo '

'; - echo 'Manuel launch / '; + echo 'Manuel launch / '; if (extension_loaded("curl")) { - echo 'Try with curl / '; + echo 'Try with curl / '; } - echo 'Try with root domain / '; - echo 'Try with OpenGraph / '; - echo 'Keep this thumbshot'; + echo 'Try with root domain / '; + echo 'Try with OpenGraph / '; + echo 'Keep this thumbshot'; echo '
'; -} -if (!empty($response) && !empty($response['error']) && $response['error'] === 1) { +} elseif (!empty($response) && !empty($response['error']) && $response['error'] === 1) { echo '
'; echo '

', $response['msg'], '

'; - echo 'Manuel launch / '; + echo '

'; + echo 'Manuel launch / '; if (extension_loaded("curl")) { - echo 'Try with curl / '; + echo 'Try with curl / '; } - echo 'Try with root domain / '; - echo 'Try with OpenGraph / '; - echo 'Keep this thumbshot'; + echo 'Try with root domain / '; + echo 'Try with OpenGraph / '; + echo 'Keep this thumbshot'; echo '
'; -} \ No newline at end of file +} diff --git a/index.php b/index.php index ccc4326..0e911fa 100644 --- a/index.php +++ b/index.php @@ -618,7 +618,7 @@ function makeFavicon($hash, $url, $filePath) if (!is_dir($hashPath)) { mkdir($hashPath, 0700, true); } - exec('convert -background transparent ' . escapeshellarg($tmpFile[' . $key . ']) . ' -resize x32 ' . $file, $resResize); + exec('convert -background transparent ' . escapeshellarg($tmpFile . '[' . $key . ']') . ' -resize x32 ' . $file, $resResize); unlink('cache/tmp/' . $hash . '.' . $data['ext']); } } else { @@ -629,9 +629,11 @@ function makeFavicon($hash, $url, $filePath) unlink('cache/tmp/' . $hash . '.' . $data['ext']); } - //n_print($data); if (file_exists($file)) { return $file; + } else { + file_put_contents($file, file_get_contents('bin/error_fav.png')); + return $file; } } @@ -721,7 +723,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' && 'normal' => 'bin/error.png', 'thumb' => 'bin/error_thumb.png', 'complete' => 'bin/error.png', - 'favicon' => 'bin/error.png', + 'favicon' => 'bin/error_fav.png', ); } } else { diff --git a/readme.md b/readme.md index 98c3650..717f106 100644 --- a/readme.md +++ b/readme.md @@ -8,6 +8,7 @@ All info in the homepage http://forge.leslibres.org/projects/soshot **Thanks** * Icon by http://www.iconfinder.com/icondetails/7917/128/camera_file_image_icon + * Icon by https://www.iconfinder.com/icons/34267/browser_earth_global_globe_international_internet_map_planet_world_icon * Bash script idea by http://www.cambus.net/blog/page/3/ * Httpstatus in bash by https://gist.github.com/rsvp/1171304 * The engine phantomjs by http://phantomjs.org/