1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Utility class for managing the temporary upload directory |
4
|
|
|
* |
5
|
|
|
* @package Jam |
6
|
|
|
* @author Ivan Kerin |
7
|
|
|
* @copyright (c) 2011-2012 Despark Ltd. |
8
|
|
|
* @license http://creativecommons.org/licenses/by-sa/3.0/legalcode |
9
|
|
|
*/ |
10
|
|
|
class Kohana_Upload_Temp |
11
|
|
|
{ |
12
|
24 |
|
public static function factory() |
13
|
|
|
{ |
14
|
24 |
|
return new Upload_Temp; |
15
|
|
|
} |
16
|
|
|
|
17
|
19 |
|
public static function config($name = NULL) |
18
|
|
|
{ |
19
|
19 |
|
if ($name !== NULL) |
20
|
|
|
{ |
21
|
19 |
|
return Kohana::$config->load("jam.upload.temp.{$name}"); |
22
|
|
|
} |
23
|
|
|
else |
24
|
|
|
{ |
25
|
|
|
return Kohana::$config->load("jam.upload.temp"); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function valid($file) |
30
|
|
|
{ |
31
|
|
|
return (substr_count($file, DIRECTORY_SEPARATOR) === 1 AND is_file(Upload_Util::combine(Upload_Temp::config('path'), $file))); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected $_directory; |
35
|
|
|
|
36
|
22 |
|
public function directory($directory = NULL) |
37
|
|
|
{ |
38
|
22 |
|
if ($directory !== NULL) |
39
|
|
|
{ |
40
|
5 |
|
$this->_directory = $directory; |
41
|
5 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
22 |
|
if ( ! $this->_directory) |
45
|
|
|
{ |
46
|
17 |
|
$this->_directory = uniqid(); |
47
|
|
|
} |
48
|
|
|
|
49
|
22 |
|
return $this->_directory; |
50
|
|
|
} |
51
|
|
|
|
52
|
15 |
|
public function directory_path($thumbnail = NULL) |
53
|
|
|
{ |
54
|
15 |
|
$directory = $this->realpath($this->directory(), $thumbnail); |
55
|
|
|
|
56
|
15 |
|
if ( ! is_dir($directory)) |
57
|
|
|
{ |
58
|
15 |
|
mkdir($directory, 0777); |
59
|
|
|
} |
60
|
|
|
|
61
|
15 |
|
return $directory; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function directory_url($thumbnail = NULL) |
65
|
|
|
{ |
66
|
|
|
return $this->webpath($this->directory(), $thumbnail); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
19 |
|
public function clear() |
70
|
|
|
{ |
71
|
19 |
|
if ($this->_directory) |
72
|
|
|
{ |
73
|
17 |
|
Upload_Util::rmdir($this->realpath($this->directory())); |
74
|
17 |
|
$this->_directory = NULL; |
75
|
|
|
} |
76
|
19 |
|
} |
77
|
|
|
|
78
|
19 |
|
public function realpath($path, $thumbnail = NULL) |
79
|
|
|
{ |
80
|
19 |
|
return Upload_Util::combine(Upload_Temp::config('path'), $path, $thumbnail); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function url($path, $thumbnail = NULL) |
84
|
|
|
{ |
85
|
|
|
return Upload_Util::combine(Upload_Temp::config('web'), $path, $thumbnail); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.