diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-07-04 07:51:19 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2019-01-28 18:02:51 +0100 |
commit | e01630006051bd91641d11f132846f7e0d845da1 (patch) | |
tree | 59354b266ca090010ca01ad4702bc4b20b8bc648 /application/service | |
parent | f707604ddadf27482ea7700932065cba6c828427 (diff) |
WIP: Add preview of text pastes to historydev-text-paste-preview
- Performance needs to be improved by putting the preview text into the
database instead of fetching it on each call.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/service')
-rw-r--r-- | application/service/files.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/application/service/files.php b/application/service/files.php index a98e0873f..a0db41b1f 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -26,6 +26,29 @@ class files { if (\libraries\Image::type_supported($item["mimetype"])) { $item['thumbnail'] = site_url("file/thumbnail/".$item['id']); } + + // FIXME performance is baaaaad here. put this in the db and populate when uploading + $filedata = $CI->mfile->get_filedata($item['id']); + $file = $CI->mfile->file($filedata["data_id"]); + $pygments = new \libraries\Pygments($file, $item['mimetype'], $item['filename']); + if ($pygments->should_highlight()) { + $max_preview_len = 1024; + $max_lines = 15; + + try { + $f = fopen($file, "r"); + } catch (\ErrorException $e) { + $f = null; + } + + if ($f) { + $text = fread($f, $max_preview_len); + fclose($f); + + $item['preview_text'] = self::ellipsize($text, $max_lines, filesize($file)); + } + } + $items[$item["id"]] = $item; } |