From: Christian Weiske Date: Sun, 15 Apr 2012 20:12:44 +0000 (+0200) Subject: do not show text field for binary files X-Git-Tag: v0.1.0~33 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/670d927b0cdc6cea596e35676676aef8f36080bc do not show text field for binary files --- diff --git a/data/templates/edit-file.htm b/data/templates/edit-file.htm index 53c2c01..a1993c5 100644 --- a/data/templates/edit-file.htm +++ b/data/templates/edit-file.htm @@ -14,7 +14,13 @@

Type determined from filename

+ {% if not file or file.isText %} + {% else %} +

+ Binary files cannot be edited. +

+ {% endif %}
diff --git a/src/phorkie/File.php b/src/phorkie/File.php index 519413d..53925ee 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -115,6 +115,22 @@ class File $tm = new Tool_Manager(); return $tm->getSuitable($this); } + + /** + * Tells if the file contains textual content and is editable. + * + * @return boolean + */ + public function isText() + { + $ext = $this->getExt(); + if (!isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) { + return false; + } + + $type = $GLOBALS['phorkie']['languages'][$ext]['mime']; + return substr($type, 0, 5) === 'text/'; + } } ?> \ No newline at end of file diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index 471cbd8..045bba1 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -94,7 +94,7 @@ class Repository_Post ->addArgument($file->getFilename()) ->execute(); $bChanged = true; - } else if ($bNew || $file->getContent() != $arFile['content']) { + } else if ($bNew || (isset($arFile['content']) && $file->getContent() != $arFile['content'])) { file_put_contents($file->getPath(), $arFile['content']); $command = $vc->getCommand('add') ->addArgument($file->getFilename())