This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
/
CartManager.php
78 lines (69 loc) · 2.87 KB
/
CartManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
namespace Pydio\Action\Cart;
use Pydio\Core\Controller\Controller;
use Pydio\Core\PluginFramework\Plugin;
use Pydio\Core\PluginFramework\PluginsService;
/**
* Class CartManager
* @package Pydio\Action\Cart
*/
class CartManager extends Plugin
{
/**
* @param \Psr\Http\Message\ServerRequestInterface $requestInterface
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @throws \Pydio\Core\Exception\ActionNotFoundException
* @throws \Pydio\Core\Exception\AuthRequiredException
*/
public function switchAction(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
if ($requestInterface->getAttribute("action") != "search-cart-download") {
return;
}
// Pipe SEARCH + DOWNLOAD actions.
$ctx = $requestInterface->getAttribute("ctx");
$indexer = PluginsService::getInstance($ctx)->getUniqueActivePluginForType("index");
if ($indexer == false) return;
$httpVars = $requestInterface->getParsedBody();
unset($httpVars["get_action"]);
$requestInterface = $requestInterface->withAttribute("action", "search")->withParsedBody($httpVars);
$response = Controller::run($requestInterface);
$body = $response->getBody();
if ($body instanceof \Pydio\Core\Http\Response\SerializableResponseStream) {
$chunks = $body->getChunks();
foreach ($chunks as $chunk) {
if ($chunk instanceof \Pydio\Access\Core\Model\NodesList) {
$res = $chunk->getChildren();
}
}
}
if (isSet($res) && is_array($res)) {
$newHttpVars = array(
"selection_nodes" => $res,
"dir" => "__AJXP_ZIP_FLAT__/",
"archive_name" => $httpVars["archive_name"]
);
$requestInterface = $requestInterface->withAttribute("action", "download")->withParsedBody($newHttpVars);
$responseInterface = Controller::run($requestInterface);
}
}
}