aboutsummaryrefslogtreecommitdiff
path: root/lib/contents.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/contents.php')
-rw-r--r--lib/contents.php72
1 files changed, 2 insertions, 70 deletions
diff --git a/lib/contents.php b/lib/contents.php
index 5b39bb66..c1eb5ad5 100644
--- a/lib/contents.php
+++ b/lib/contents.php
@@ -1,9 +1,5 @@
<?php
-final class HttpException extends \Exception
-{
-}
-
// todo: move this somewhere useful, possibly into a function
const RSSBRIDGE_HTTP_STATUS_CODES = [
'100' => 'Continue',
@@ -128,7 +124,8 @@ function getContents(
}
$cache->saveData($result['body']);
break;
- case 304: // Not Modified
+ case 304:
+ // Not Modified
$response['content'] = $cache->loadData();
break;
default:
@@ -379,68 +376,3 @@ function getSimpleHTMLDOMCached(
$defaultSpanText
);
}
-
-/**
- * Determines the MIME type from a URL/Path file extension.
- *
- * _Remarks_:
- *
- * * The built-in functions `mime_content_type` and `fileinfo` require fetching
- * remote contents.
- * * A caller can hint for a MIME type by appending `#.ext` to the URL (i.e. `#.image`).
- *
- * Based on https://stackoverflow.com/a/1147952
- *
- * @param string $url The URL or path to the file.
- * @return string The MIME type of the file.
- */
-function getMimeType($url)
-{
- static $mime = null;
-
- if (is_null($mime)) {
- // Default values, overriden by /etc/mime.types when present
- $mime = [
- 'jpg' => 'image/jpeg',
- 'gif' => 'image/gif',
- 'png' => 'image/png',
- 'image' => 'image/*',
- 'mp3' => 'audio/mpeg',
- ];
- // '@' is used to mute open_basedir warning, see issue #818
- if (@is_readable('/etc/mime.types')) {
- $file = fopen('/etc/mime.types', 'r');
- while (($line = fgets($file)) !== false) {
- $line = trim(preg_replace('/#.*/', '', $line));
- if (!$line) {
- continue;
- }
- $parts = preg_split('/\s+/', $line);
- if (count($parts) == 1) {
- continue;
- }
- $type = array_shift($parts);
- foreach ($parts as $part) {
- $mime[$part] = $type;
- }
- }
- fclose($file);
- }
- }
-
- if (strpos($url, '?') !== false) {
- $url_temp = substr($url, 0, strpos($url, '?'));
- if (strpos($url, '#') !== false) {
- $anchor = substr($url, strpos($url, '#'));
- $url_temp .= $anchor;
- }
- $url = $url_temp;
- }
-
- $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
- if (!empty($mime[$ext])) {
- return $mime[$ext];
- }
-
- return 'application/octet-stream';
-}