|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
|
6
|
|
|
* @package MW |
|
7
|
|
|
* @subpackage View |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\MW\View\Helper\Url; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* TYPO3 view helper class for building URLs on the command line |
|
16
|
|
|
* |
|
17
|
|
|
* @package MW |
|
18
|
|
|
* @subpackage View |
|
19
|
|
|
*/ |
|
20
|
|
|
class T3Cli |
|
21
|
|
|
extends \Aimeos\MW\View\Helper\Url\Base |
|
22
|
|
|
implements \Aimeos\MW\View\Helper\Url\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
private $baseurl; |
|
25
|
|
|
private $prefix; |
|
26
|
|
|
private $fixed; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initializes the URL view helper. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Aimeos\MW\View\Iface $view View instance with registered view helpers |
|
33
|
|
|
* @param string $baseurl Base URL, e.g. http://localhost/index.php |
|
34
|
|
|
* @param string $prefix Argument prefix, e.g. "ai" for "ai[key]=value" |
|
35
|
|
|
* @param array $fixed Fixed parameters that should be added to each URL |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( \Aimeos\MW\View\Iface $view, $baseurl, $prefix, array $fixed ) |
|
38
|
|
|
{ |
|
39
|
|
|
\Aimeos\MW\View\Helper\Base::__construct( $view ); |
|
40
|
|
|
|
|
41
|
|
|
$this->baseurl = $baseurl; |
|
42
|
|
|
$this->prefix = $prefix; |
|
43
|
|
|
$this->fixed = $fixed; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns the URL assembled from the given arguments. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string|null $target Route or page which should be the target of the link (if any) |
|
51
|
|
|
* @param string|null $controller Name of the controller which should be part of the link (if any) |
|
52
|
|
|
* @param string|null $action Name of the action which should be part of the link (if any) |
|
53
|
|
|
* @param array $params Associative list of parameters that should be part of the URL |
|
54
|
|
|
* @param array $trailing Trailing URL parts that are not relevant to identify the resource (for pretty URLs) |
|
55
|
|
|
* @param array $config Additional configuration parameter per URL |
|
56
|
|
|
* @return string Complete URL that can be used in the template |
|
57
|
|
|
*/ |
|
58
|
|
|
public function transform( $target = null, $controller = null, $action = null, array $params = array(), array $trailing = array(), array $config = array() ) |
|
59
|
|
|
{ |
|
60
|
|
|
$arguments = $this->fixed; |
|
61
|
|
|
$arguments['controller'] = $controller; |
|
62
|
|
|
$arguments['action'] = $action; |
|
63
|
|
|
|
|
64
|
|
|
if( $this->prefix ) |
|
65
|
|
|
{ |
|
66
|
|
|
if( isset( $config['namespace'] ) && $config['namespace'] == false ) { |
|
67
|
|
|
$params = $params + array( $this->prefix => $arguments ); |
|
68
|
|
|
} else { |
|
69
|
|
|
$params = array( $this->prefix => array_merge( $arguments, $params ) ); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
else |
|
73
|
|
|
{ |
|
74
|
|
|
$params = array_merge( $params, $arguments ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$params = array_merge( $params, $this->getValues( $config ) ); |
|
78
|
|
|
$params = $this->sanitize( $params ); |
|
79
|
|
|
|
|
80
|
|
|
return $this->baseurl . '?id=' . $target . '&' . http_build_query( $params ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Returns the sanitized configuration values. |
|
86
|
|
|
* |
|
87
|
|
|
* @param array $config Associative list of key/value pairs |
|
88
|
|
|
* @return array Associative list of sanitized key/value pairs |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getValues( array $config ) |
|
91
|
|
|
{ |
|
92
|
|
|
$values = array(); |
|
93
|
|
|
|
|
94
|
|
|
if( isset( $config['plugin'] ) ) { |
|
95
|
|
|
$values['plugin'] = (string) $config['plugin']; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if( isset( $config['extension'] ) ) { |
|
99
|
|
|
$values['extension'] = (string) $config['extension']; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if( isset( $config['nocache'] ) ) { |
|
103
|
|
|
$values['no_cache'] = (bool) $config['nocache']; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if( isset( $config['type'] ) ) { |
|
107
|
|
|
$values['type'] = (int) $config['type']; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if( isset( $config['eID'] ) ) { |
|
111
|
|
|
$values['eID'] = $config['eID']; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $values; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|