function safepath($root, $path) { if ($root === false) { return false; } $path = urealpath($root . $path); $root = urealpath($root); if ($root === false || $path === false) { return false; } $len = strlen($root); if (substr($path, 0, $len) == $root) { if (strlen($path) == $len) { return ''; } return substr($path, $len); } return false; }
ucopy($CFG['tempdir'] . $thash . '.jpg', $CFG['cachedir'] . $hash . '_' . $size . '.jpg'); touch($CFG['cachedir'] . $hash . '_' . $size . '.jpg', ufiletime($rootdir . $file), $_now); uunlink($CFG['tempdir'] . $thash . '.jpg'); } myunlock($thash); } } elseif (isweb($file)) { if (newer($rootdir . $file, $CFG['cachedir'] . $hash . '_' . $size . '.jpg')) { mylock($thash) || exit; if (!ufile_exists($CFG['tempdir'] . $thash . '.png')) { while (ufile_exists($CFG['tempdir'] . 'firefox.lock')) { sleep(rand(5, 15)); } utouch($CFG['tempdir'] . 'firefox' . '.lock'); file_put_contents($CFG['tempdir'] . 'firefox' . '.lock', $thash); $cmd = $firefox . ' -no-remote -profile ' . escapeshellarg($ffprofile) . ' -saveimage ' . escapeshellarg('file:///' . r(urealpath($rootdir . $file))) . ' -savedelay 100 -witdh 1024'; #logger($cmd); exe($cmd); ucopy($ffdownload . 'shot.png', $CFG['tempdir'] . $thash . '.png'); uunlink($ffdownload . 'shot.png'); uunlink($CFG['tempdir'] . 'firefox' . '.lock'); $cmd = $imagemagick_identify . ' -format "%wx%h" ' . escapeshellarg($CFG['tempdir'] . $thash . '.png'); list($w, $h) = explode('x', trim(exe($cmd))); $A4 = 297 / 210; if ($h / $w > $A4) { $h = intval($w * $A4); ucopy($CFG['tempdir'] . $thash . '.png', $CFG['tempdir'] . $thash . '_0.png'); uunlink($CFG['tempdir'] . $thash . '.png'); $cmd = $imagemagick_convert . ' -crop "' . $w . 'x' . $h . '+0+0" ' . escapeshellarg($CFG['tempdir'] . $thash . '_0.png') . ' ' . escapeshellarg($CFG['tempdir'] . $thash . '.png'); exe($cmd); uunlink($CFG['tempdir'] . $thash . '_0.png');