Skip to content

Commit

Permalink
Adjusting formatting for functions in compatability.php. photo#638
Browse files Browse the repository at this point in the history
  • Loading branch information
jmathai committed Sep 25, 2014
1 parent 8a801c8 commit 520cab8
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/libraries/compatability.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@ function array_column($array, $column)
}

// parse_ini_string is >= 5.3
if(!function_exists('parse_ini_string')){
function parse_ini_string($str, $ProcessSections=false){
$lines = explode("\n", $str);
$return = Array();
$inSect = false;
foreach($lines as $line){
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]")){
$inSect = substr($line, 1, $endIdx-1);
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
continue;

$tmp = explode("=", $line, 2);
$tmp[1] = preg_replace(array('/^ ?"/', '/"$/'), '', $tmp[1]);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
else
$return[trim($tmp[0])] = ltrim($tmp[1]);
}
return $return;
if(!function_exists('parse_ini_string'))
{
function parse_ini_string($str, $ProcessSections=false)
{
$lines = explode("\n", $str);
$return = Array();
$inSect = false;
foreach($lines as $line)
{
$line = trim($line);
if(!$line || $line[0] == "#" || $line[0] == ";")
continue;
if($line[0] == "[" && $endIdx = strpos($line, "]"))
{
$inSect = substr($line, 1, $endIdx-1);
continue;
}
if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
continue;

$tmp = explode("=", $line, 2);
$tmp[1] = preg_replace(array('/^ ?"/', '/"$/'), '', $tmp[1]);
if($ProcessSections && $inSect)
$return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
else
$return[trim($tmp[0])] = ltrim($tmp[1]);
}
return $return;
}
}

// finfo_open is >= 5.3
Expand All @@ -45,19 +49,19 @@ function get_mime_type($filename)
$type = null;
if(function_exists("finfo_open"))
{
// not supported everywhere https://github.com/openphoto/frontend/issues/368
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $filename);
// not supported everywhere https://github.com/openphoto/frontend/issues/368
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $filename);
}
else if(function_exists("mime_content_type"))
{
$type = mime_content_type($filename);
$type = mime_content_type($filename);
}
else if(function_exists('exec'))
{
$type = exec('/usr/bin/file --mime-type -b ' .escapeshellarg($filename));
if(empty($type))
$type = null;
$type = exec('/usr/bin/file --mime-type -b ' .escapeshellarg($filename));
if(empty($type))
$type = null;
}

return $type;
Expand Down

0 comments on commit 520cab8

Please sign in to comment.