Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"require": {
"php": ">=5.3.9",
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-json": "*",
"erusev/parsedown-extra": "^0.7.0",
Expand Down Expand Up @@ -41,7 +42,6 @@
"symfony/console": "^2.7.5"
},
"suggest": {
"ext-fileinfo": "*",
"ext-imagick": "*",
"ext-ldap": "*",
"ext-memcached": "*",
Expand Down
6 changes: 3 additions & 3 deletions core/controllers/components/DownloadBitstreamComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ function env($key)
{
if ($key == 'HTTPS') {
if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
}

return (strpos(env('SCRIPT_URI'), 'https://') === 0);
return strpos(env('SCRIPT_URI'), 'https://') === 0;
}

if ($key == 'SCRIPT_NAME') {
Expand Down Expand Up @@ -217,7 +217,7 @@ function env($key)
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
break;
case 'CGI_MODE':
return (PHP_SAPI === 'cgi');
return PHP_SAPI === 'cgi';
break;
case 'HTTP_BASE':
$host = env('HTTP_HOST');
Expand Down
16 changes: 8 additions & 8 deletions core/controllers/components/MimeTypeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
class MimeTypeComponent extends AppComponent
{
/**
* Get mime type.
* Get MIME type.
*
* @param string $filename
* @param null|string $alternateName
* @return string
*/
public function getType($filename, $alternateName = null)
{
if (function_exists('finfo_open') && file_exists($filename)) {
if (file_exists($filename)) {
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($fileInfo, $filename);
finfo_close($fileInfo);
if ($mimeType) {
if ($mimeType !== false) {
return $mimeType;
}
}
Expand All @@ -55,7 +55,7 @@ public function getType($filename, $alternateName = null)
* @param string $filename
* @return string
*/
public function privFindType($filename)
private function privFindType($filename)
{
// get base name of the filename provided by user
$filename = basename($filename);
Expand All @@ -72,18 +72,18 @@ public function privFindType($filename)
// return mime type for extension
if (isset($mimeTypes[$filename])) {
return $mimeTypes[$filename];
// if the extension wasn't found return octet-stream
} else {
return 'application/octet-stream';
}

// If the extension was not found, return octet-stream.
return 'application/octet-stream';
}

/**
* privBuildMimeArray.
*
* @return array
*/
public function privBuildMimeArray()
private function privBuildMimeArray()
{
return array(
'123' => 'application/vnd.lotus-1-2-3',
Expand Down
4 changes: 2 additions & 2 deletions library/KWUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function createSubDirectories($baseDirectory, $subDirectories, $mo
*/
public static function isWindows()
{
return (strtolower(substr(PHP_OS, 0, 3)) == 'win');
return strtolower(substr(PHP_OS, 0, 3)) == 'win';
}

/**
Expand Down Expand Up @@ -162,7 +162,7 @@ public static function exec($command, &$output = null, $chdir = '', &$return_val
*/
public static function isLinux()
{
return (strtolower(substr(PHP_OS, 0, 5)) == 'linux');
return strtolower(substr(PHP_OS, 0, 5)) == 'linux';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/oai/library/oai/oaidp-util.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function get_token()
{
list($usec, $sec) = explode(' ', microtime());

return ((int) ($usec * 1000) + (int) ($sec * 1000));
return (int) ($usec * 1000) + (int) ($sec * 1000);
}

function oai_error($code, $argument = '', $value = '')
Expand Down Expand Up @@ -429,7 +429,7 @@ function php_is_at_least($version)

function is_valid_uri($url)
{
return ((bool) preg_match("'^[^:]+:(?://)?(?:[a-z_0-9-]+[\.]{1})*(?:[a-z_0-9-]+\.)[a-z]{2,3}.*$'i", $url));
return (bool) preg_match("'^[^:]+:(?://)?(?:[a-z_0-9-]+[\.]{1})*(?:[a-z_0-9-]+\.)[a-z]{2,3}.*$'i", $url);
}

function metadataHeader($prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,179 +20,6 @@

include_once BASE_PATH.'/library/KWUtils.php';

if (extension_loaded('fileinfo') === false) {
define('FILEINFO_NONE', 0);
define('FILEINFO_SYMLINK', 2);
define('FILEINFO_DEVICES', 8);
define('FILEINFO_CONTINUE', 32);
define('FILEINFO_PRESERVE_ATIME', 128);
define('FILEINFO_RAW', 256);
define('FILEINFO_MIME_TYPE', 16);
define('FILEINFO_MIME_ENCODING', 1024);
define('FILEINFO_MIME', 1040);

/**
* Return information about a given string.
*
* @param null|int|resource $finfo fileinfo resource
* @param null|string $string content of the file to be checked
* @param int $options fileinfo constant (FILEINFO_NONE | FILEINFO_MIME_TYPE | FILEINFO_MIME_ENCODING | FILEINFO_MIME)
* @param null|resource $context context (not implemented)
* @return false|string a textual description of the given string or false on failure
*/
function finfo_buffer($finfo, $string = null, $options = FILEINFO_NONE, $context = null)
{
if ($finfo !== false && !is_null($string) && is_null($context)) {
if ($options === FILEINFO_NONE && (($finfo & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE || ($finfo & FILEINFO_MIME_ENCODING) === FILEINFO_MIME_ENCODING)) {
$options = $finfo;
}

if (($options & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE || ($options & FILEINFO_MIME_ENCODING) === FILEINFO_MIME_ENCODING) {
$mimeEncoding = 'binary';

if (substr($string, 0, 8) === "\x89PNG\x0d\x0a\x1a\x0a") {
$mimeType = 'image/png';
} elseif (substr($string, 0, 6) === 'GIF87a' || substr($string, 0, 6) === 'GIF89a') {
$mimeType = 'image/gif';
} elseif (substr($string, 0, 4) === "MM\x00\x2a" || substr($string, 0, 4) === "II\x2a\x00") {
$mimeType = 'image/tiff';
} elseif (substr($string, 0, 4) === '8BPS') {
$mimeType = 'image/vnd.adobe.photoshop';
} elseif (substr($string, 0, 3) === "\xFF\xD8\xFF") {
$mimeType = 'image/jpeg';
} elseif (substr($string, 0, 2) === 'BM') {
$mimeType = 'image/bmp';
} elseif (strpos($string, "\x00") !== false) {
$mimeType = 'application/octet-stream';
} else {
$mimeEncoding = 'utf-8';
$mimeType = 'text/plain';
}

if (($options & FILEINFO_MIME) === FILEINFO_MIME) {
return $mimeType.'; charset='.$mimeEncoding;
}

if (($options & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE) {
return $mimeType;
}

return $mimeEncoding;
}
}

return false;
}

/**
* Close a given fileinfo resource.
*
* @param null|resource $finfo fileinfo resource
* @return bool true on success or false on failure
*/
function finfo_close($finfo)
{
return $finfo !== false;
}

/**
* Return information about a given file.
*
* @param null|int|resource $finfo fileinfo resource
* @param null|string $filename name of the file to be checked
* @param int $options fileinfo constant (FILEINFO_NONE | FILEINFO_MIME_TYPE | FILEINFO_MIME_ENCODING | FILEINFO_MIME)
* @param null|resource $context context (partially implemented)
* @return false|string a textual description of the contents of the given file or false on failure
*/
function finfo_file($finfo, $filename = null, $options = FILEINFO_NONE, $context = null)
{
if ($finfo !== false && !is_null($filename)) {
if ($options === FILEINFO_NONE && (($finfo & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE || ($finfo & FILEINFO_MIME_ENCODING) === FILEINFO_MIME_ENCODING)) {
$options = $finfo;
}

if (($options & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE || ($options & FILEINFO_MIME_ENCODING) === FILEINFO_MIME_ENCODING) {
$mimeType = finfo_buffer($finfo, file_get_contents($filename, false, $context), $options, $context);

if ($mimeType === false || $mimeType === 'application/octet-stream') {
$extension = strtolower(end(explode('.', basename($filename))));

switch ($extension) {
case 'bmp':
$mimeType = 'image/bmp';
break;
case 'gif':
$mimeType = 'image/gif';
break;
case 'ico':
$mimeType = 'image/x-icon';
break;
case 'jpe':
case 'jpeg':
case 'jpg':
$mimeType = 'image/jpeg';
break;
case 'png':
$mimeType = 'image/png';
break;
case 'psd':
$mimeType = 'image/vnd.adobe.photoshop';
break;
case 'tif':
case 'tiff':
$mimeType = 'image/tiff';
break;
case 'text':
case 'txt':
$mimeType = 'text/plain';
break;
default:
$mimeType = 'application/octet-stream';
}
}

$mimeEncoding = $mimeType === 'text/plain' ? 'utf-8' : 'binary';

if (($options & FILEINFO_MIME) === FILEINFO_MIME) {
return $mimeType.'; charset='.$mimeEncoding;
}

if (($options & FILEINFO_MIME_TYPE) === FILEINFO_MIME_TYPE) {
return $mimeType;
}

return $mimeEncoding;
}
}

return false;
}

/**
* Create a new fileinfo resource.
*
* @param int $options fileinfo constant (FILEINFO_NONE | FILEINFO_MIME_TYPE | FILEINFO_MIME_ENCODING | FILEINFO_MIME)
* @param null|string $magic name of a magic database file (not implemented)
* @return null|int|resource a fileinfo resource on success or false on failure.
*/
function finfo_open($options = FILEINFO_NONE, $magic = null)
{
return is_null($magic) ? $options : false;
}

/**
* Set the magic configuration options (not implemented).
*
* @param null|int|resource $finfo fileinfo resource
* @param int $options fileinfo constant (FILEINFO_NONE | FILEINFO_MIME_TYPE | FILEINFO_MIME_ENCODING | FILEINFO_MIME)
* @return bool true on success or false on failure
*/
function finfo_set_flags($finfo, $options)
{
return $finfo === $options;
}
}

/** Component used to create thumbnails using phMagick library (on top of ImageMagick) */
class Thumbnailcreator_ImagemagickComponent extends AppComponent
{
Expand Down