|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Creates the target url for files and downloads |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Core |
|
9
|
|
|
* @package URL |
|
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
11
|
|
|
* @copyright 2013 cSphere Team |
|
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
13
|
|
|
* @link http://www.csphere.eu |
|
14
|
|
|
**/ |
|
15
|
|
|
|
|
16
|
|
|
namespace csphere\core\url; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Creates the target url for files and downloads |
|
20
|
|
|
* |
|
21
|
|
|
* PHP Version 5 |
|
22
|
|
|
* |
|
23
|
|
|
* @category Core |
|
24
|
|
|
* @package URL |
|
25
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
|
26
|
|
|
* @copyright 2013 cSphere Team |
|
27
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
|
28
|
|
|
* @link http://www.csphere.eu |
|
29
|
|
|
**/ |
|
30
|
|
|
|
|
31
|
|
|
abstract class Load |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Checks if options are fetched already |
|
35
|
|
|
**/ |
|
36
|
|
|
private static $_init = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Stores the dirname part of links |
|
40
|
|
|
**/ |
|
41
|
|
|
private static $_prefix = ''; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Fetch options and set flags |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
**/ |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
private static function _init() |
|
50
|
|
|
{ |
|
51
|
|
|
self::$_prefix = \csphere\core\http\Request::get('dirname'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Set details for a plugin image |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $plugin Plugin of image file |
|
58
|
|
|
* @param string $directory Image subdirectory that cannot be empty |
|
59
|
|
|
* @param string $name Name of image file |
|
60
|
|
|
* @param string $extension File extension with "png" as default value |
|
61
|
|
|
* |
|
62
|
|
|
* @throws \Exception |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
**/ |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public static function image($plugin, $directory, $name, $extension = 'png') |
|
68
|
|
|
{ |
|
69
|
|
|
// Check and set options if init is not done yet |
|
70
|
|
|
if (self::$_init == false) { |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
self::_init(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (!preg_match("=^[_a-z0-9-]+$=i", $name)) { |
|
76
|
|
|
|
|
77
|
|
|
throw new \Exception('Name of plugin image contains unallowed chars'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$image = self::$_prefix |
|
81
|
|
|
. 'csphere/plugins/' |
|
82
|
|
|
. $plugin |
|
83
|
|
|
. '/images/' |
|
84
|
|
|
. $directory |
|
85
|
|
|
. '/' |
|
86
|
|
|
. $name |
|
87
|
|
|
. '.' |
|
88
|
|
|
. $extension; |
|
89
|
|
|
|
|
90
|
|
|
return $image; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|