|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
|
7
|
|
|
* @package MW |
|
8
|
|
|
* @subpackage View |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MW\View\Helper\Content; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* View helper class for generating media URLs |
|
17
|
|
|
* |
|
18
|
|
|
* @package MW |
|
19
|
|
|
* @subpackage View |
|
20
|
|
|
*/ |
|
21
|
|
|
class Standard |
|
22
|
|
|
extends \Aimeos\MW\View\Helper\Base |
|
23
|
|
|
implements \Aimeos\MW\View\Helper\Content\Iface |
|
24
|
|
|
{ |
|
25
|
|
|
private $baseurls = []; |
|
26
|
|
|
private $enc; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initializes the content view helper. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Aimeos\MW\View\Iface $view View instance with registered view helpers |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( \Aimeos\MW\View\Iface $view ) |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct( $view ); |
|
37
|
|
|
$this->enc = $view->encoder(); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns the complete encoded content URL. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string|null $url Absolute, relative or data: URL |
|
45
|
|
|
* @param string $fsname File system name the file is stored at |
|
46
|
|
|
* @return string Complete encoded content URL |
|
47
|
|
|
*/ |
|
48
|
|
|
public function transform( ?string $url, $fsname = 'fs-media' ) : string |
|
49
|
|
|
{ |
|
50
|
|
|
if( $url && !\Aimeos\MW\Str::starts( $url, ['http', 'data:', '/'] ) ) { |
|
51
|
|
|
$url = $this->baseurl( $fsname ) . '/' . $url; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this->enc->attr( $url ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the base URL for the given file system. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $fsname File system name |
|
62
|
|
|
* @return string Base URL of the file system |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function baseurl( string $fsname ) : string |
|
65
|
|
|
{ |
|
66
|
|
|
if( !isset( $this->baseurls[$fsname] ) ) { |
|
67
|
|
|
$this->baseurls[$fsname] = rtrim( $this->getView()->config( 'resource/' . $fsname . '/baseurl' ), '/' ); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->baseurls[$fsname]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|