-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessor.php
executable file
·67 lines (56 loc) · 1.8 KB
/
Processor.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
<?php
/**
* Imanage_Processor
*
* @category Addon
* @package addon.imanage
* @author Ebine Yutaka <[email protected]>
* @copyright 2004-2008 Mori Reo <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
class Imanage_Processor extends Sabel_Bus_Processor
{
protected $afterEvents = array("controller" => "setImanage");
/**
* @var Imanage_Object
*/
protected $imanage = null;
public function execute(Sabel_Bus $bus)
{
$iConfig = new Imanage_Config();
$config = $iConfig->configure();
$this->imanage = new Imanage_Object($config);
if (($request = $bus->get("request")) === null) {
return;
}
if (!$request->isGet()) {
return;
}
$parts = array();
$fixed = true;
$uri = "/" . $request->getUri();
if (strpos($uri, $config["thumbnail_uri"] . "/") === 0) {
$parts = explode("/", substr($uri, strlen($config["thumbnail_uri"]) + 1));
} elseif (strpos($uri, $config["resize_uri"] . "/") === 0) {
$parts = explode("/", substr($uri, strlen($config["resize_uri"]) + 1));
$fixed = false;
}
if (!empty($parts)) {
@list ($size, , , $fileName) = $parts;
@list ($height, $width) = explode("x", $size);
if (!is_natural_number($height) || !is_natural_number($width)) {
$bus->get("response")->getStatus()->setCode(Sabel_Response::BAD_REQUEST);
} elseif ($this->imanage->thumbnail($fileName, $height, $width, true, $fixed)) {
exit;
} else {
$bus->get("response")->getStatus()->setCode(Sabel_Response::NOT_FOUND);
}
}
}
public function setImanage($bus)
{
if ($controller = $bus->get("controller")) {
$controller->setAttribute("imanage", $this->imanage);
}
}
}