summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-08-20 14:31:31 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-08-20 14:31:31 +0200
commitc9d3f108266a8179f3a4e1ca8b09553e16f2a312 (patch)
tree7d39a033d1b01233b73610c8f22cf2921aba466e
parente840564d14cdeb1c774464953cf8d45a8b083550 (diff)
Decouple output_cache from CI for easier testing
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/file.php28
-rw-r--r--application/libraries/Output_cache.php4
2 files changed, 17 insertions, 15 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index 139496eb9..d882b9334 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -171,7 +171,7 @@ class File extends MY_Controller {
exit();
}
- $this->load->library("output_cache");
+ $output_cache = new \libraries\Output_cache();
foreach ($files as $key => $filedata) {
$file = $this->mfile->file($filedata['data_id']);
@@ -211,16 +211,16 @@ class File extends MY_Controller {
if (\libraries\Image::type_supported($mimetype)) {
$filedata["tooltip"] = $this->_tooltip_for_image($filedata);
$filedata["orientation"] = libraries\Image::get_exif_orientation($file);
- $this->output_cache->add_merge(
+ $output_cache->add_merge(
array("items" => array($filedata)),
'file/fragments/thumbnail'
);
} else if ($base == "audio") {
- $this->output_cache->add(array("filedata" => $filedata), "file/fragments/audio-player");
+ $output_cache->add(array("filedata" => $filedata), "file/fragments/audio-player");
} else if ($base == "video") {
- $this->output_cache->add(array("filedata" => $filedata), "file/fragments/video-player");
+ $output_cache->add(array("filedata" => $filedata), "file/fragments/video-player");
} else {
- $this->output_cache->add_merge(
+ $output_cache->add_merge(
array("items" => array($filedata)),
'file/fragments/uploads_table'
);
@@ -230,10 +230,10 @@ class File extends MY_Controller {
}
if ($lexer == "asciinema") {
- $this->output_cache->add(array("filedata" => $filedata), "file/fragments/asciinema-player");
+ $output_cache->add(array("filedata" => $filedata), "file/fragments/asciinema-player");
} else {
- $this->output_cache->add_function(function() use ($filedata, $lexer, $is_multipaste) {
- $this->_highlight_file($filedata, $lexer, $is_multipaste);
+ $output_cache->add_function(function() use ($output_cache, $filedata, $lexer, $is_multipaste) {
+ $this->_highlight_file($output_cache, $filedata, $lexer, $is_multipaste);
});
}
}
@@ -246,7 +246,7 @@ class File extends MY_Controller {
// much magic ({elapsed_time} and {memory_usage}).
// Direct echo puts us on the safe side.
echo $this->load->view($this->var->view_dir.'/html_header', $this->data, true);
- $this->output_cache->render();
+ $output_cache->render();
echo $this->load->view($this->var->view_dir.'/html_footer', $this->data, true);
}
@@ -315,7 +315,7 @@ class File extends MY_Controller {
);
}
- private function _highlight_file($filedata, $lexer, $is_multipaste)
+ private function _highlight_file($output_cache, $filedata, $lexer, $is_multipaste)
{
// highlight the file and cache the result, fall back to plain text if $lexer fails
foreach (array($lexer, "text") as $lexer) {
@@ -351,7 +351,7 @@ class File extends MY_Controller {
if ($lexer != "text") {
$message .= " Falling back to plain text.";
}
- $this->output_cache->render_now(
+ $output_cache->render_now(
array("error_message" => "<p>$message</p>"),
"file/fragments/alert-wide"
);
@@ -366,9 +366,9 @@ class File extends MY_Controller {
'filedata' => $filedata,
));
- $this->output_cache->render_now($data, $this->var->view_dir.'/html_paste_header');
- $this->output_cache->render_now($highlit["output"]);
- $this->output_cache->render_now($data, $this->var->view_dir.'/html_paste_footer');
+ $output_cache->render_now($data, $this->var->view_dir.'/html_paste_header');
+ $output_cache->render_now($highlit["output"]);
+ $output_cache->render_now($data, $this->var->view_dir.'/html_paste_footer');
}
private function _tooltip_for_image($filedata)
diff --git a/application/libraries/Output_cache.php b/application/libraries/Output_cache.php
index 224e9f95a..1d8339887 100644
--- a/application/libraries/Output_cache.php
+++ b/application/libraries/Output_cache.php
@@ -1,12 +1,14 @@
<?php
/*
- * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ * Copyright 2014,2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
*
* Licensed under AGPLv3
* (see COPYING for full license text)
*
*/
+namespace libraries;
+
class Output_cache {
private $output_cache = array();