From 64421d76fdd8b718c3f0fccf94ba0028adc593b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Nov 2014 12:37:59 +0100 Subject: Deduplicate function by moving it to the OC_Helper --- lib/private/helper.php | 17 +++++++++++++++++ lib/private/preview/movies.php | 12 ++---------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/private/helper.php b/lib/private/helper.php index 5b1d31bfc59..be448b8ff9b 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -872,6 +872,23 @@ class OC_Helper { return true; } + /** + * Try to find a program + * Note: currently windows is not supported + * + * @param string $program + * @return null|string + */ + public static function findBinaryPath($program) { + if (!\OC_Util::runningOnWindows() && self::is_function_enabled('exec')) { + exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); + if ($returnCode === 0 && count($output) > 0) { + return escapeshellcmd($output[0]); + } + } + return null; + } + /** * Calculate the disc space for the given path * diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index 2a23c2141c1..8217ad24409 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -8,14 +8,6 @@ */ namespace OC\Preview; -function findBinaryPath($program) { - exec('command -v ' . escapeshellarg($program) . ' 2> /dev/null', $output, $returnCode); - if ($returnCode === 0 && count($output) > 0) { - return escapeshellcmd($output[0]); - } - return null; -} - // movie preview is currently not supported on Windows if (!\OC_Util::runningOnWindows()) { $isExecEnabled = \OC_Helper::is_function_enabled('exec'); @@ -23,9 +15,9 @@ if (!\OC_Util::runningOnWindows()) { $avconvBinary = null; if ($isExecEnabled) { - $avconvBinary = findBinaryPath('avconv'); + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); if (!$avconvBinary) { - $ffmpegBinary = findBinaryPath('ffmpeg'); + $ffmpegBinary = \OC_Helper::findBinaryPath('ffmpeg'); } } -- cgit v1.2.3