function ewww_image_optimizer_path_check($j = true, $o = true, $g = true, $p = true, $q = true, $w = true) { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_path_check()</b><br>"; $jpegtran = false; $optipng = false; $gifsicle = false; $pngout = false; $pngquant = false; $webp = false; if (EWWW_IMAGE_OPTIMIZER_NOEXEC) { return array('JPEGTRAN' => false, 'OPTIPNG' => false, 'GIFSICLE' => false, 'PNGOUT' => false, 'PNGQUANT' => false, 'WEBP' => false); } // for Windows, everything must be in the wp-content/ewww folder, so that is all we check if ('WINNT' == PHP_OS) { if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran.exe') && $j) { $jpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran.exe'; $ewww_debug .= "found {$jpt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $jpt . '"', 'j') && ewww_image_optimizer_md5check($jpt)) { $jpegtran = '"' . $jpt . '"'; } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng.exe') && $o) { $opt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng.exe'; $ewww_debug .= "found {$opt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $opt . '"', 'o') && ewww_image_optimizer_md5check($opt)) { $optipng = '"' . $opt . '"'; } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle.exe') && $g) { $gpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle.exe'; $ewww_debug .= "found {$gpt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $gpt . '"', 'g') && ewww_image_optimizer_md5check($gpt)) { $gifsicle = '"' . $gpt . '"'; } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout.exe') && $p) { $ppt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout.exe'; $ewww_debug .= "found {$ppt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $ppt . '"', 'p') && ewww_image_optimizer_md5check($ppt)) { $pngout = '"' . $ppt . '"'; } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant.exe') && $q) { $qpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant.exe'; $ewww_debug .= "found {$qpt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $qpt . '"', 'q') && ewww_image_optimizer_md5check($qpt)) { $pngquant = '"' . $qpt . '"'; } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp.exe') && $w) { $wpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp.exe'; $ewww_debug .= "found {$wpt}, testing...<br>"; if (ewww_image_optimizer_tool_found('"' . $wpt . '"', 'w') && ewww_image_optimizer_md5check($wpt)) { $webp = '"' . $wpt . '"'; } } } else { // check to see if the user has disabled using bundled binaries $use_system = ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle'); if ($j) { // first check for the jpegtran binary in the ewww tool folder if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran') && !$use_system) { $jpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran'; $ewww_debug .= "found {$jpt}, testing...<br>"; if (ewww_image_optimizer_md5check($jpt) && ewww_image_optimizer_mimetype($jpt, 'b')) { $jpt = ewww_image_optimizer_escapeshellcmd($jpt); if (ewww_image_optimizer_tool_found($jpt, 'j')) { $jpegtran = $jpt; } } } // if the standard jpegtran binary didn't work, see if the user custom compiled one and check that if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-custom') && !$jpegtran && !$use_system) { $jpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-custom'; $ewww_debug .= "found {$jpt}, testing...<br>"; if (filesize($jpt) > 15000 && ewww_image_optimizer_mimetype($jpt, 'b')) { $jpt = ewww_image_optimizer_escapeshellcmd($jpt); if (ewww_image_optimizer_tool_found($jpt, 'j')) { $jpegtran = $jpt; } } } // see if the alternative binary works if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-alt') && !$jpegtran && !$use_system) { $jpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-alt'; $ewww_debug .= "found {$jpt}, testing...<br>"; if (filesize($jpt) > 15000 && ewww_image_optimizer_mimetype($jpt, 'b')) { $jpt = ewww_image_optimizer_escapeshellcmd($jpt); if (ewww_image_optimizer_tool_found($jpt, 'j')) { $jpegtran = $jpt; } } } // if we still haven't found a usable binary, try a system-installed version if (!$jpegtran) { $jpegtran = ewww_image_optimizer_find_binary('jpegtran', 'j'); } } if ($o) { if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng') && !$use_system) { $opt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng'; $ewww_debug .= "found {$opt}, testing...<br>"; if (ewww_image_optimizer_md5check($opt) && ewww_image_optimizer_mimetype($opt, 'b')) { $opt = ewww_image_optimizer_escapeshellcmd($opt); if (ewww_image_optimizer_tool_found($opt, 'o')) { $optipng = $opt; } } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng-custom') && !$optipng && !$use_system) { $opt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng-custom'; $ewww_debug .= "found {$opt}, testing...<br>"; if (filesize($opt) > 15000 && ewww_image_optimizer_mimetype($opt, 'b')) { $opt = ewww_image_optimizer_escapeshellcmd($opt); if (ewww_image_optimizer_tool_found($opt, 'o')) { $optipng = $opt; } } } if (!$optipng) { $optipng = ewww_image_optimizer_find_binary('optipng', 'o'); } } if ($g) { if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle') && !$use_system) { $gpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle'; $ewww_debug .= "found {$gpt}, testing...<br>"; if (ewww_image_optimizer_md5check($gpt) && ewww_image_optimizer_mimetype($gpt, 'b')) { $gpt = ewww_image_optimizer_escapeshellcmd($gpt); if (ewww_image_optimizer_tool_found($gpt, 'g')) { $gifsicle = $gpt; } } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle-custom') && !$gifsicle && !$use_system) { $gpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle-custom'; $ewww_debug .= "found {$gpt}, testing...<br>"; if (filesize($gpt) > 15000 && ewww_image_optimizer_mimetype($gpt, 'b')) { $gpt = ewww_image_optimizer_escapeshellcmd($gpt); if (ewww_image_optimizer_tool_found($gpt, 'g')) { $gifsicle = $gpt; } } } if (!$gifsicle) { $gifsicle = ewww_image_optimizer_find_binary('gifsicle', 'g'); } } if ($p) { // pngout is special and has a dynamic and static binary to check if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static') && !$use_system) { $ppt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngout-static'; $ewww_debug .= "found {$ppt}, testing...<br>"; if (ewww_image_optimizer_md5check($ppt) && ewww_image_optimizer_mimetype($ppt, 'b')) { $ppt = ewww_image_optimizer_escapeshellcmd($ppt); if (ewww_image_optimizer_tool_found($ppt, 'p')) { $pngout = $ppt; } } } if (!$pngout) { $pngout = ewww_image_optimizer_find_binary('pngout', 'p'); } if (!$pngout) { $pngout = ewww_image_optimizer_find_binary('pngout-static', 'p'); } } if ($q) { if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant') && !$use_system) { $qpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant'; $ewww_debug .= "found {$qpt}, testing...<br>"; if (ewww_image_optimizer_md5check($qpt) && ewww_image_optimizer_mimetype($qpt, 'b')) { $qpt = ewww_image_optimizer_escapeshellcmd($qpt); if (ewww_image_optimizer_tool_found($qpt, 'q')) { $pngquant = $qpt; } } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant-custom') && !$pngquant && !$use_system) { $qpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'pngquant-custom'; $ewww_debug .= "found {$qpt}, testing...<br>"; if (filesize($qpt) > 15000 && ewww_image_optimizer_mimetype($qpt, 'b')) { $qpt = ewww_image_optimizer_escapeshellcmd($qpt); if (ewww_image_optimizer_tool_found($qpt, 'q')) { $pngquant = $qpt; } } } if (!$pngquant) { $pngquant = ewww_image_optimizer_find_binary('pngquant', 'q'); } } if ($w) { if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp') && !$use_system) { $wpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp'; $ewww_debug .= "found {$wpt}, testing...<br>"; if (ewww_image_optimizer_md5check($wpt) && ewww_image_optimizer_mimetype($wpt, 'b')) { $wpt = ewww_image_optimizer_escapeshellcmd($wpt); if (ewww_image_optimizer_tool_found($wpt, 'w')) { $webp = $wpt; } } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp-custom') && !$webp && !$use_system) { $wpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp-custom'; $ewww_debug .= "found {$wpt}, testing...<br>"; if (filesize($wpt) > 5000 && ewww_image_optimizer_mimetype($wpt, 'b')) { $wpt = ewww_image_optimizer_escapeshellcmd($wpt); if (ewww_image_optimizer_tool_found($wpt, 'w')) { $webp = $wpt; } } } if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp-alt') && !$webp && !$use_system) { $wpt = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'cwebp-alt'; $ewww_debug .= "found {$wpt}, testing...<br>"; if (filesize($wpt) > 5000 && ewww_image_optimizer_mimetype($wpt, 'b')) { $wpt = ewww_image_optimizer_escapeshellcmd($wpt); if (ewww_image_optimizer_tool_found($wpt, 'w')) { $webp = $wpt; } } } if (!$webp) { $webp = ewww_image_optimizer_find_binary('cwebp', 'w'); } } } if ($jpegtran) { $ewww_debug .= "using: {$jpegtran}<br>"; } if ($optipng) { $ewww_debug .= "using: {$optipng}<br>"; } if ($gifsicle) { $ewww_debug .= "using: {$gifsicle}<br>"; } if ($pngout) { $ewww_debug .= "using: {$pngout}<br>"; } if ($pngquant) { $ewww_debug .= "using: {$pngquant}<br>"; } if ($webp) { $ewww_debug .= "using: {$webp}<br>"; } ewwwio_memory(__FUNCTION__); return array('JPEGTRAN' => $jpegtran, 'OPTIPNG' => $optipng, 'GIFSICLE' => $gifsicle, 'PNGOUT' => $pngout, 'PNGQUANT' => $pngquant, 'WEBP' => $webp); }
function ewww_image_optimizer_install_tools() { global $ewww_debug; $ewww_debug .= "<b>ewww_image_optimizer_install_tools()</b><br>"; $ewww_debug .= "Checking/Installing tools in " . EWWW_IMAGE_OPTIMIZER_TOOL_PATH . "<br>"; $toolfail = false; if (!is_dir(EWWW_IMAGE_OPTIMIZER_TOOL_PATH)) { $ewww_debug .= "Folder doesn't exist, creating...<br>"; if (!mkdir(EWWW_IMAGE_OPTIMIZER_TOOL_PATH)) { echo "<div id='ewww-image-optimizer-warning-tool-install' class='error'><p><strong>" . __('EWWW Image Optimizer could not create the tool folder', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ": " . htmlentities(EWWW_IMAGE_OPTIMIZER_TOOL_PATH) . ".</strong> " . __('Please adjust permissions or create the folder', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ".</p></div>"; $ewww_debug .= "Couldn't create folder<br>"; } } else { $ewww_perms = substr(sprintf('%o', fileperms(EWWW_IMAGE_OPTIMIZER_TOOL_PATH)), -4); $ewww_debug .= "wp-content/ewww permissions: {$ewww_perms} <br />"; } list($jpegtran_src, $optipng_src, $gifsicle_src, $pngquant_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst, $pngquant_dst) = ewww_image_optimizer_install_paths(); if (!file_exists($jpegtran_dst)) { $ewww_debug .= "jpegtran not found, installing<br>"; if (!copy($jpegtran_src, $jpegtran_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy jpegtran<br>"; } } else { if (filesize($jpegtran_dst) != filesize($jpegtran_src)) { $ewww_debug .= "jpegtran found, different size, attempting to replace<br>"; if (!copy($jpegtran_src, $jpegtran_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy jpegtran<br>"; } } } // install 32-bit jpegtran at jpegtran-custom for some weird 64-bit hosts $arch_type = php_uname('m'); if (PHP_OS == 'Linux' && $arch_type == 'x86_64') { $ewww_debug .= "64-bit linux detected while installing tools<br>"; $jpegtran32_src = substr($jpegtran_src, 0, -2); $jpegtran32_dst = $jpegtran_dst . '-custom'; if (!file_exists($jpegtran32_dst) || ewww_image_optimizer_md5check($jpegtran32_dst) && filesize($jpegtran32_dst) != filesize($jpegtran32_src)) { $ewww_debug .= "copying {$jpegtran32_src} to {$jpegtran32_dst}<br>"; if (!copy($jpegtran32_src, $jpegtran32_dst)) { // this isn't a fatal error, besides we'll see it in the debug if needed $ewww_debug .= "Couldn't copy 32-bit jpegtran to jpegtran-custom<br>"; } $jpegtran32_perms = substr(sprintf('%o', fileperms($jpegtran32_dst)), -4); $ewww_debug .= "jpegtran-custom (32-bit) permissions: {$jpegtran32_perms}<br>"; if ($jpegtran32_perms != '0755') { if (!chmod($jpegtran32_dst, 0755)) { $ewww_debug .= "couldn't set jpegtran-custom permissions<br>"; } } } } if (!file_exists($gifsicle_dst)) { $ewww_debug .= "gifsicle not found, installing<br>"; if (!copy($gifsicle_src, $gifsicle_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy gifsicle<br>"; } } else { if (filesize($gifsicle_dst) != filesize($gifsicle_src)) { $ewww_debug .= "gifsicle found, different size, attempting to replace<br>"; if (!copy($gifsicle_src, $gifsicle_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy gifsicle<br>"; } } } if (!file_exists($optipng_dst)) { $ewww_debug .= "optipng not found, installing<br>"; if (!copy($optipng_src, $optipng_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy optipng<br>"; } } else { if (filesize($optipng_dst) != filesize($optipng_src)) { $ewww_debug .= "optipng found, different size, attempting to replace<br>"; if (!copy($optipng_src, $optipng_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy optipng<br>"; } } } if (!file_exists($pngquant_dst)) { $ewww_debug .= "pngquant not found, installing<br>"; if (!copy($pngquant_src, $pngquant_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy pngquant<br>"; } } else { if (filesize($pngquant_dst) != filesize($pngquant_src)) { $ewww_debug .= "pngquant found, different size, attempting to replace<br>"; if (!copy($pngquant_src, $pngquant_dst)) { $toolfail = true; $ewww_debug .= "Couldn't copy pngquant<br>"; } } } if (PHP_OS != 'WINNT') { $ewww_debug .= "Linux/UNIX style OS, checking permissions<br>"; $jpegtran_perms = substr(sprintf('%o', fileperms($jpegtran_dst)), -4); $ewww_debug .= "jpegtran permissions: {$jpegtran_perms}<br>"; if ($jpegtran_perms != '0755') { if (!chmod($jpegtran_dst, 0755)) { $toolfail = true; $ewww_debug .= "couldn't set jpegtran permissions<br>"; } } $gifsicle_perms = substr(sprintf('%o', fileperms($gifsicle_dst)), -4); $ewww_debug .= "gifsicle permissions: {$gifsicle_perms}<br>"; if ($gifsicle_perms != '0755') { if (!chmod($gifsicle_dst, 0755)) { $toolfail = true; $ewww_debug .= "couldn't set gifsicle permissions<br>"; } } $optipng_perms = substr(sprintf('%o', fileperms($optipng_dst)), -4); $ewww_debug .= "optipng permissions: {$optipng_perms}<br>"; if ($optipng_perms != '0755') { if (!chmod($optipng_dst, 0755)) { $toolfail = true; $ewww_debug .= "couldn't set optipng permissions<br>"; } } $pngquant_perms = substr(sprintf('%o', fileperms($pngquant_dst)), -4); $ewww_debug .= "pngquant permissions: {$pngquant_perms}<br>"; if ($pngquant_perms != '0755') { if (!chmod($pngquant_dst, 0755)) { $toolfail = true; $ewww_debug .= "couldn't set pngquant permissions<br>"; } } } if ($toolfail) { echo "<div id='ewww-image-optimizer-warning-tool-install' class='error'><p><strong>" . sprintf(__('EWWW Image Optimizer could not install tools in %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), htmlentities(EWWW_IMAGE_OPTIMIZER_TOOL_PATH)) . ".</strong> " . sprintf(__('Please adjust permissions or create the folder. If you have installed the tools elsewhere on your system, check the option to %s.', EWWW_IMAGE_OPTIMIZER_DOMAIN), __('Use System Paths', EWWW_IMAGE_OPTIMIZER_DOMAIN)) . " " . sprintf(__('For more details, visit the %1$s or the %2$s.', EWWW_IMAGE_OPTIMIZER_DOMAIN), "<a href='options-general.php?page=ewww-image-optimizer/ewww-image-optimizer.php'>" . __('Settings Page', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a>", "<a href='http://wordpress.org/extend/plugins/ewww-image-optimizer/installation/'>" . __('Installation Instructions', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</a>.</p></div>"); } $migrate_fail = false; if ($jpegtran_path = ewww_image_optimizer_get_option('ewww_image_optimizer_jpegtran_path')) { $ewww_debug .= "found path setting for jpegtran, migrating<br>"; if (file_exists($jpegtran_path)) { $ewww_debug .= "found custom jpegtran binary<br>"; if (!copy($jpegtran_path, EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-custom') || !chmod(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'jpegtran-custom', 0755)) { $ewww_debug .= "unable to copy custom jpegtran binary or set permissions<br>"; $migrate_fail = true; } else { delete_option('ewww_image_optimizer_jpegtran_path'); $ewww_debug .= "migration successful, deleting path setting<br>"; } } } if ($optipng_path = ewww_image_optimizer_get_option('ewww_image_optimizer_optipng_path')) { $ewww_debug .= "found path setting for optipng, migrating<br>"; if (file_exists($optipng_path)) { $ewww_debug .= "found custom optipng binary<br>"; if (!copy($optipng_path, EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng-custom') || !chmod(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'optipng-custom', 0755)) { $ewww_debug .= "unable to copy custom optipng binary or set permissions<br>"; $migrate_fail = true; } else { delete_option('ewww_image_optimizer_optipng_path'); $ewww_debug .= "migration successful, deleting path setting<br>"; } } } if ($gifsicle_path = ewww_image_optimizer_get_option('ewww_image_optimizer_gifsicle_path')) { $ewww_debug .= "found path setting for gifsicle, migrating<br>"; if (file_exists($gifsicle_path)) { $ewww_debug .= "found custom gifsicle binary<br>"; if (!copy($gifsicle_path, EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle-custom') || !chmod(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . 'gifsicle-custom', 0755)) { $ewww_debug .= "unable to copy custom gifislce binary or set permissions<br>"; $migrate_fail = true; } else { delete_option('ewww_image_optimizer_gifsicle_path'); $ewww_debug .= "migration successful, deleting path setting<br>"; } } } if ($migrate_fail) { echo "<div id='ewww-image-optimizer-warning-tool-install' class='error'><p><strong>" . sprintf(__('EWWW Image Optimizer attempted to move your custom-built binaries to %s but the operation was unsuccessful', EWWW_IMAGE_OPTIMIZER_DOMAIN), htmlentities(EWWW_IMAGE_OPTIMIZER_TOOL_PATH)) . ".</strong> " . __('Please adjust the permissions on this folder', EWWW_IMAGE_OPTIMIZER_DOMAIN) . ".</p></div>"; } }
function ewww_image_optimizer_find_nix_binary($binary, $switch) { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); if (empty($binary) || empty($switch)) { return ''; } $use_system = ewww_image_optimizer_get_option('ewww_image_optimizer_skip_bundle'); // first check for the binary in the ewww tool folder if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary) && !$use_system) { $binary_path = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary; ewwwio_debug_message("found {$binary_path}, testing..."); if (ewww_image_optimizer_md5check($binary_path) && ewww_image_optimizer_mimetype($binary_path, 'b')) { $binary_path = ewww_image_optimizer_escapeshellcmd($binary_path); if (ewww_image_optimizer_tool_found($binary_path, $switch)) { return $binary_path; } } } // if the standard binary didn't work, see if the user custom compiled one and check that if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary . '-custom') && !$use_system) { $binary_path = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary . '-custom'; ewwwio_debug_message("found {$binary_path}, testing..."); if (filesize($binary_path) > 15000 && ewww_image_optimizer_mimetype($binary_path, 'b')) { $binary_path = ewww_image_optimizer_escapeshellcmd($binary_path); if (ewww_image_optimizer_tool_found($binary_path, $switch)) { return $binary_path; } } } // see if the alternative binary works if (file_exists(EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary . '-alt') && !$use_system) { $binary_path = EWWW_IMAGE_OPTIMIZER_TOOL_PATH . $binary . '-alt'; ewwwio_debug_message("found {$binary_path}, testing..."); if (filesize($binary_path) > 15000 && ewww_image_optimizer_mimetype($binary_path, 'b')) { $binary_path = ewww_image_optimizer_escapeshellcmd($binary_path); if (ewww_image_optimizer_tool_found($binary_path, $switch)) { return $binary_path; } } } // if we still haven't found a usable binary, try a system-installed version if (ewww_image_optimizer_tool_found($binary, $switch)) { return $binary; } elseif (ewww_image_optimizer_tool_found('/usr/bin/' . $binary, $switch)) { return '/usr/bin/' . $binary; } elseif (ewww_image_optimizer_tool_found('/usr/local/bin/' . $binary, $switch)) { return '/usr/local/bin/' . $binary; } elseif (ewww_image_optimizer_tool_found('/usr/gnu/bin/' . $binary, $switch)) { return '/usr/gnu/bin/' . $binary; } elseif (ewww_image_optimizer_tool_found('/usr/syno/bin/' . $binary, $switch)) { // for synology diskstation OS return '/usr/syno/bin/' . $binary; } else { return ''; } }