summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-04-09 14:44:47 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-04-09 14:49:33 +0200
commit7e36fe6d9c4b6a791ac68aeb62dddd08522904d9 (patch)
treedef335009b79dfb7d2748c4a410cd9cace55d10e
parent814c2b44fcc500d2f8f2acb7c9443079908ddaa2 (diff)
Improve title for multipastes
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php37
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();