summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/config/routes.php1
-rw-r--r--application/controllers/file/multipaste.php113
-rw-r--r--application/service/multipaste_queue.php85
-rw-r--r--application/views/file/multipaste/queue.php32
4 files changed, 231 insertions, 0 deletions
diff --git a/application/config/routes.php b/application/config/routes.php
index 9583ff37c..f44f283f0 100644
--- a/application/config/routes.php
+++ b/application/config/routes.php
@@ -40,6 +40,7 @@
$route['default_controller'] = "file/file_default";
$route['user/(:any)'] = "user/$1";
+$route['file/multipaste/(:any)'] = "file/multipaste/$1";
$route['file/(:any)'] = "file/file_default/$1";
$route['tools/(:any)'] = "tools/$1";
$route['api/(:any)'] = "api/route/$1";
diff --git a/application/controllers/file/multipaste.php b/application/controllers/file/multipaste.php
new file mode 100644
index 000000000..00efb2403
--- /dev/null
+++ b/application/controllers/file/multipaste.php
@@ -0,0 +1,113 @@
+<?php
+/*
+ * Copyright 2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+class Multipaste extends MY_Controller {
+
+ function __construct() {
+ parent::__construct();
+
+ $this->load->model('mfile');
+ $this->load->model('mmultipaste');
+ }
+
+ public function append_multipaste_queue() {
+ $this->muser->require_access("basic");
+
+ $ids = $this->input->post("ids");
+ if ($ids === false) {
+ $ids = [];
+ }
+
+ $m = new \service\multipaste_queue();
+ $m->append($ids);
+
+ redirect("file/multipaste/queue");
+ }
+
+ public function review_multipaste() {
+ $this->muser->require_access("basic");
+
+ $this->load->view('header', $this->data);
+ $this->load->view('file/review_multipaste', $this->data);
+ $this->load->view('footer', $this->data);
+ }
+
+ public function queue() {
+ $this->muser->require_access("basic");
+
+ $m = new \service\multipaste_queue();
+ $ids = $m->get();
+
+ $this->data['ids'] = $ids;
+ $this->data['items'] = array_map(function($id) {return $this->_get_multipaste_item($id);}, $ids);
+
+ $this->load->view('header', $this->data);
+ $this->load->view('file/multipaste/queue', $this->data);
+ $this->load->view('footer', $this->data);
+ }
+
+ public function form_submit() {
+ $this->muser->require_access("basic");
+
+ $ids = $this->input->post('ids');
+ $process = $this->input->post('process');
+
+ if ($ids === false) {
+ $ids = [];
+ }
+
+ $m = new \service\multipaste_queue();
+ $m->set($ids);
+
+ $dispatcher = [
+ 'save' => function() use ($ids, $m) {
+ redirect("file/multipaste/queue");
+ },
+ 'create' => function() use ($ids, $m) {
+ $userid = $this->muser->get_userid();
+ $limits = $this->muser->get_upload_id_limits();
+ $ret = \service\files::create_multipaste($ids, $userid, $limits);
+ $m->set([]);
+ redirect($ret['url_id']);
+ },
+ ];
+
+ if (isset($dispatcher[$process])) {
+ $dispatcher[$process]();
+ } else {
+ throw new \exceptions\UserInputException("file/multipaste/form_submit/invalid-process-value", "Value in process field not found in dispatch table");
+ }
+ }
+
+ public function ajax_submit() {
+ $this->muser->require_access("basic");
+ $ids = $this->input->post('ids');
+
+ if ($ids === false) {
+ $ids = [];
+ }
+
+ $m = new \service\multipaste_queue();
+ $m->set($ids);
+ }
+
+ private function _get_multipaste_item($id) {
+ $filedata = $this->mfile->get_filedata($id);
+ $item = [];
+ $item['id'] = $filedata['id'];
+ $item['tooltip'] = \service\files::tooltip($filedata);
+ $item['title'] = $filedata['filename'];
+ if (\libraries\Image::type_supported($filedata["mimetype"])) {
+ $item['thumbnail'] = site_url("file/thumbnail/".$filedata['id']);
+ }
+
+ return $item;
+ }
+
+}
diff --git a/application/service/multipaste_queue.php b/application/service/multipaste_queue.php
new file mode 100644
index 000000000..1836eeacb
--- /dev/null
+++ b/application/service/multipaste_queue.php
@@ -0,0 +1,85 @@
+<?php
+/*
+ * Copyright 2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+namespace service;
+
+class multipaste_queue {
+
+ public function __construct() {
+ $CI =& get_instance();
+ $CI->load->model("mfile");
+ $CI->load->model("mmultipaste");
+ $this->session = $CI->session;
+ $this->mfile = $CI->mfile;
+ $this->mmultipaste = $CI->mmultipaste;
+ }
+
+ /**
+ * Append ids to the queue
+ *
+ * @param array ids
+ * @return void
+ */
+ public function append(array $ids) {
+ $old_ids = $this->get();
+
+ $old_ids = $this->get();
+
+ # replace multipaste ids with their corresponding paste ids
+ $ids = array_map(function($id) {return array_values($this->resolve_multipaste($id));}, $ids);
+ $ids = array_reduce($ids, function($a, $b) {return array_merge($a, $b);}, []);
+
+ $ids = array_unique(array_merge($old_ids, $ids));
+ $this->set($ids);
+ }
+
+ /**
+ * Return array of ids in a multipaste if the argument id is a multipaste.
+ * Otherwise return an array containing just the argument id.
+ *
+ * @param id
+ * @return array of ids
+ */
+ private function resolve_multipaste($id) {
+ if (strpos($id, "m-") === 0) {
+ if ($this->mmultipaste->valid_id($id)) {
+ return array_map(function($filedata) {return $filedata['id'];}, $this->mmultipaste->get_files($id));
+ }
+ }
+ return [$id];
+ }
+
+ /**
+ * Get the queue
+ *
+ * @return array of ids
+ */
+ public function get() {
+ $ids = $this->session->userdata("multipaste_queue");
+ if ($ids === false) {
+ $ids = [];
+ }
+
+ assert(is_array($ids));
+ return $ids;
+ }
+
+ /**
+ * Set the queue to $ids
+ *
+ * @param array ids
+ * @return void
+ */
+ public function set(array $ids) {
+ $ids = array_filter($ids, function($id) {return $this->mfile->valid_id($id);});
+
+ $this->session->set_userdata("multipaste_queue", $ids);
+ }
+
+}
diff --git a/application/views/file/multipaste/queue.php b/application/views/file/multipaste/queue.php
new file mode 100644
index 000000000..3f42b3cdf
--- /dev/null
+++ b/application/views/file/multipaste/queue.php
@@ -0,0 +1,32 @@
+<div class="multipasteQueue">
+ <?php echo form_open("file/multipaste/form_submit", ["data-ajax_url" => site_url("file/multipaste/ajax_submit")]); ?>
+ <div class="items"><!--
+ <?php foreach ($items as $item) {?>
+ --><div data-id="<?php echo $item['id']; ?>">
+ <input type="hidden" name="ids[<?php echo $item['id']; ?>]" value="<?php echo $item['id']; ?>">
+ <div class='item'>
+ <?php if (isset($item['thumbnail'])) { ?>
+ <img
+ src="<?php echo $item['thumbnail']; ?>"
+ title="<?php echo $item['title']; ?>"
+ data-content="<?php echo $item['tooltip']; ?>">
+ <?php } else { ?>
+ <div>
+ <?php echo $item['title']; ?><br>
+ <?php echo $item['tooltip']; ?>
+ </div>
+ <?php } ?>
+ </div>
+ <button class='multipaste_queue_delete btn-danger btn btn-xs'>Remove</button>
+ </div><!--
+ <?php } ?>
+ --></div>
+ <button type="submit" class="btn btn-default" name="process" value="save">
+ <div class="ajaxFeedback" style="display: none">
+ <span class="glyphicon glyphicon-refresh spinning"></span>
+ </div>
+ Only save queue order
+ </button>
+ <button type="submit" class="btn btn-primary" name="process" value="create">Create multipaste</button>
+ </form>
+</div>