1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Advertisement management. An extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2017 phpBB Limited <https://www.phpbb.com> |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace phpbb\ads\banner; |
12
|
|
|
|
13
|
|
|
class banner |
14
|
|
|
{ |
15
|
|
|
/** @var \phpbb\files\upload */ |
16
|
|
|
protected $files_upload; |
17
|
|
|
|
18
|
|
|
/** @var \phpbb\filesystem\filesystem_interface */ |
19
|
|
|
protected $filesystem; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $root_path; |
23
|
|
|
|
24
|
|
|
/** @var \phpbb\files\filespec */ |
25
|
|
|
protected $file; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor |
29
|
|
|
* |
30
|
|
|
* @param \phpbb\files\upload $files_upload Files upload object |
31
|
|
|
* @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem object |
32
|
|
|
* @param string $root_path Root path |
33
|
|
|
*/ |
34
|
7 |
|
public function __construct(\phpbb\files\upload $files_upload, \phpbb\filesystem\filesystem_interface $filesystem, $root_path) |
35
|
|
|
{ |
36
|
7 |
|
$this->files_upload = $files_upload; |
37
|
7 |
|
$this->filesystem = $filesystem; |
38
|
7 |
|
$this->root_path = $root_path; |
39
|
7 |
|
} |
40
|
|
|
|
41
|
3 |
|
public function set_file($file) |
42
|
|
|
{ |
43
|
3 |
|
$this->file = $file; |
44
|
3 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create storage directory for banners uploaded by Ads Management |
48
|
|
|
*/ |
49
|
4 |
|
public function create_storage_dir() |
50
|
|
|
{ |
51
|
4 |
|
if (!$this->filesystem->exists($this->root_path . 'images/phpbb_ads')) |
52
|
4 |
|
{ |
53
|
2 |
|
$this->filesystem->mkdir($this->root_path . 'images/phpbb_ads'); |
54
|
1 |
|
} |
55
|
3 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Handle banner upload |
59
|
|
|
*/ |
60
|
2 |
|
public function upload() |
61
|
|
|
{ |
62
|
|
|
// Set file restrictions |
63
|
2 |
|
$this->files_upload->reset_vars(); |
64
|
2 |
|
$this->files_upload->set_allowed_extensions(array('gif', 'jpg', 'jpeg', 'png')); |
65
|
|
|
|
66
|
|
|
// Upload file |
67
|
2 |
|
$this->set_file($this->files_upload->handle_upload('files.types.form', 'banner')); |
68
|
2 |
|
$this->file->clean_filename('unique_ext'); |
69
|
|
|
|
70
|
|
|
// Move file to proper location |
71
|
2 |
|
if (!$this->file->move_file('images/phpbb_ads')) |
72
|
2 |
|
{ |
73
|
1 |
|
$this->file->set_error('FILE_MOVE_UNSUCCESSFUL'); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
2 |
|
if (count($this->file->error)) |
77
|
2 |
|
{ |
78
|
1 |
|
throw new \phpbb\exception\runtime_exception($this->file->error[0]); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
return $this->file->get('realname'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Remove file from the filesystem |
86
|
|
|
*/ |
87
|
1 |
|
public function remove() |
88
|
|
|
{ |
89
|
1 |
|
$this->file->remove(); |
90
|
1 |
|
} |
91
|
|
|
} |
92
|
|
|
|