diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-04-09 14:44:47 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-04-09 14:49:33 +0200 |
commit | 7e36fe6d9c4b6a791ac68aeb62dddd08522904d9 (patch) | |
tree | def335009b79dfb7d2748c4a410cd9cace55d10e /application/controllers/file.php | |
parent | 814c2b44fcc500d2f8f2acb7c9443079908ddaa2 (diff) |
Improve title for multipastes
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/file.php')
-rw-r--r-- | application/controllers/file.php | 37 |
1 files changed, 36 insertions, 1 deletions
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(); |