diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/phorkie/Repository/Post.php | 2 | ||||
| -rw-r--r-- | src/phorkie/Tool/MIME/Type/PlainDetect.php | 35 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index c9f6a53..fbfea4b 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -232,7 +232,7 @@ class Repository_Post { $tmp = tempnam(sys_get_temp_dir(), 'phorkie-autodetect-'); file_put_contents($tmp, $content); - $type = \MIME_Type_PlainDetect::autoDetect($tmp); + $type = Tool_MIME_Type_PlainDetect::autoDetect($tmp); unlink($tmp); return $this->findExtForType($type); diff --git a/src/phorkie/Tool/MIME/Type/PlainDetect.php b/src/phorkie/Tool/MIME/Type/PlainDetect.php new file mode 100644 index 0000000..235046e --- /dev/null +++ b/src/phorkie/Tool/MIME/Type/PlainDetect.php @@ -0,0 +1,35 @@ +<?php +namespace phorkie; + +class Tool_MIME_Type_PlainDetect extends \MIME_Type_PlainDetect +{ + /** + * Try to find the magic file copied by phing's build.xml into + * lib/data/. + * + * @return string path to the magic file + */ + public static function getMagicFile() + { + $rootdir = __DIR__ . '/../../../../../'; + if (file_exists($rootdir . '/lib/PEAR.php')) { + if (!\Phar::running()) { + return $rootdir . '/lib/data/programming.magic'; + } else { + //magic file within a .phar does not work: + // https://bugs.php.net/bug.php?id=67556 + //put it outside + $target = '/tmp/phorkie-programming.magic'; + if (!file_exists($target)) { + copy( + $rootdir . '/lib/data/programming.magic', + $target + ); + } + return $target; + } + } + return parent::getMagicFile(); + } +} +?> |
