From 9ec269330c11f13bdfc3489d3000965685695ddb Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 13 Nov 2013 23:36:58 +0100 Subject: [PATCH] Dependancy extensions safety checks --- init.php | 2 +- src/Controllers/PostController.php | 9 ++++++++- src/core.php | 13 +++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/init.php b/init.php index 38481828..aa0d0728 100644 --- a/init.php +++ b/init.php @@ -50,7 +50,7 @@ download('http://raw.github.com/aehlke/tag-it/master/css/jquery.tagit.css', $lib download('http://raw.github.com/aehlke/tag-it/master/js/tag-it.min.js', $libPath . 'tagit' . DS . 'jquery.tagit.js'); //Mousetrap -download('https://raw.github.com/ccampbell/mousetrap/master/mousetrap.min.js', $libPath . 'mousetrap' . DS . 'mousetrap.min.js'); +download('http://raw.github.com/ccampbell/mousetrap/master/mousetrap.min.js', $libPath . 'mousetrap' . DS . 'mousetrap.min.js'); //fonts download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans.ttf', $fontsPath . 'DroidSans.ttf'); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index b518d65b..583c2522 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -243,7 +243,14 @@ class PostController /* file details */ - $mimeType = $sourcePath ? mime_content_type($sourcePath) : null; + $mimeType = null; + if ($sourcePath) + { + if (function_exists('mime_content_type')) + $mimeType = mime_content_type($sourcePath); + else + $mimeType = $suppliedFile['type']; + } $imageWidth = null; $imageHeight = null; switch ($mimeType) diff --git a/src/core.php b/src/core.php index 37cef1d8..55e3c1fb 100644 --- a/src/core.php +++ b/src/core.php @@ -11,16 +11,21 @@ function trueStartTime() } trueStartTime(); -require_once __DIR__ . '/../lib/php-markdown/Michelf/Markdown.php'; -require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php'; -require_once __DIR__ . '/../lib/chibi-core/Facade.php'; -require_once __DIR__ . '/../lib/chibi-core/Registry.php'; +$requiredExtensions = ['pdo', 'pdo_sqlite', 'gd', 'openssl']; +foreach ($requiredExtensions as $ext) + if (!extension_loaded($ext)) + die('PHP extension "' . $ext . '" must be enabled to continue.' . PHP_EOL); date_default_timezone_set('UTC'); setlocale(LC_CTYPE, 'en_US.UTF-8'); ini_set('memory_limit', '128M'); define('DS', DIRECTORY_SEPARATOR); +require_once __DIR__ . '/../lib/php-markdown/Michelf/Markdown.php'; +require_once __DIR__ . '/../lib/redbean/RedBean/redbean.inc.php'; +require_once __DIR__ . '/../lib/chibi-core/Facade.php'; +require_once __DIR__ . '/../lib/chibi-core/Registry.php'; + function configFactory() { static $config = null;