From 7e36fe6d9c4b6a791ac68aeb62dddd08522904d9 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 9 Apr 2015 14:44:47 +0200 Subject: Improve title for multipastes Signed-off-by: Florian Pritz --- application/controllers/file.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/application/controllers/file.php b/application/controllers/file.php index 4c9291b75..06ab4fc71 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -45,6 +45,41 @@ class File extends MY_Controller { } } + /** + * Generate a page title of the format "Multipaste - $filename, $filename, … (N more)". + * This mainly helps in IRC channels to quickly determine what is in a multipaste. + * + * @param files array of filedata + * @return title to be used + */ + private function _multipaste_page_title(array $files) + { + $filecount = count($files); + $title = "Multipaste ($filecount files) - "; + $titlenames = array(); + $len = strlen($title); + $delimiter = ', '; + $maxlen = 100; + + foreach ($files as $file) { + if ($len > $maxlen) break; + + $filename = $file['filename']; + $titlenames[] = htmlspecialchars($filename); + $len += strlen($filename) + strlen($delimiter); + } + + $title .= implode($delimiter, $titlenames); + + $leftover_count = $filecount - count($titlenames); + + if ($leftover_count > 0) { + $title .= $delimiter.'… ('.$leftover_count.' more)'; + } + + return $title; + } + function _download() { $id = $this->uri->segment(1); @@ -58,7 +93,7 @@ class File extends MY_Controller { return $this->_non_existent(); } $files = $this->mmultipaste->get_files($id); - $this->data["title"] = "Multipaste"; + $this->data["title"] = $this->_multipaste_page_title($files); } elseif ($this->mfile->id_exists($id)) { if (!$this->mfile->valid_id($id)) { return $this->_non_existent(); -- cgit v1.2.3-24-g4f1b