1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ModernTimeline; |
6
|
|
|
|
7
|
|
|
use ParamProcessor\ParameterTypes; |
8
|
|
|
use ParamProcessor\ProcessedParam; |
9
|
|
|
|
10
|
|
|
class TimelineOptions { |
11
|
|
|
|
12
|
|
|
public const PARAM_WIDTH = 'width'; |
13
|
|
|
public const PARAM_HEIGHT = 'height'; |
14
|
|
|
private const PARAM_BOOKMARK = 'bookmark'; |
15
|
|
|
private const PARAM_BACKGROUND = 'background'; |
16
|
|
|
private const PARAM_SCALE_FACTOR = 'scale factor'; |
17
|
|
|
private const PARAM_POSITION = 'position'; |
18
|
|
|
private const PARAM_TICK_WIDTH = 'tick width'; |
19
|
|
|
private const PARAM_START_SLIDE = 'start slide'; |
20
|
|
|
private const PARAM_START_AT_END = 'start at end'; |
21
|
|
|
private const PARAM_TRANSITION_DURATION = 'transition duration'; |
22
|
|
|
private const PARAM_NAV_HEIGHT = 'navigation height'; |
23
|
|
|
private const PARAM_TEMPLATE = 'template'; |
24
|
|
|
private const PARAM_IMAGE = 'image property'; |
25
|
|
|
|
26
|
23 |
|
public static function getTimelineParameterDefinitions(): array { |
27
|
23 |
|
$definitions = []; |
28
|
|
|
|
29
|
23 |
|
$definitions[self::PARAM_WIDTH] = [ |
30
|
23 |
|
'type' => ParameterTypes::DIMENSION, |
31
|
|
|
'allowauto' => true, |
32
|
|
|
'units' => [ 'px', 'ex', 'em', '%', '' ], |
33
|
23 |
|
'default' => $GLOBALS['wgModernTimelineWidth'], |
34
|
|
|
]; |
35
|
|
|
|
36
|
23 |
|
$definitions[self::PARAM_HEIGHT] = [ |
37
|
23 |
|
'type' => ParameterTypes::DIMENSION, |
38
|
|
|
'units' => [ 'px', 'ex', 'em', '' ], |
39
|
23 |
|
'default' => $GLOBALS['wgModernTimelineHeight'], |
40
|
|
|
]; |
41
|
|
|
|
42
|
23 |
|
$definitions[self::PARAM_BOOKMARK] = [ |
43
|
23 |
|
'type' => ParameterTypes::BOOLEAN, |
44
|
23 |
|
'default' => $GLOBALS['wgModernTimelineBookmark'], |
45
|
|
|
]; |
46
|
|
|
|
47
|
23 |
|
$definitions[self::PARAM_BACKGROUND] = [ |
48
|
23 |
|
'type' => ParameterTypes::STRING, |
49
|
23 |
|
'default' => $GLOBALS['wgModernTimelineBackground'], |
50
|
|
|
]; |
51
|
|
|
|
52
|
23 |
|
$definitions[self::PARAM_SCALE_FACTOR] = [ |
53
|
23 |
|
'type' => ParameterTypes::INTEGER, |
54
|
23 |
|
'default' => $GLOBALS['wgModernTimelineScaleFactor'], |
55
|
23 |
|
'lowerbound' => 1 |
56
|
|
|
]; |
57
|
|
|
|
58
|
23 |
|
$definitions[self::PARAM_POSITION] = [ |
59
|
23 |
|
'type' => ParameterTypes::STRING, |
60
|
23 |
|
'default' => $GLOBALS['wgModernTimelinePosition'], |
61
|
|
|
'values' => [ 'top', 'bottom' ], |
62
|
|
|
]; |
63
|
|
|
|
64
|
23 |
|
$definitions[self::PARAM_TICK_WIDTH] = [ |
65
|
23 |
|
'type' => ParameterTypes::INTEGER, |
66
|
23 |
|
'default' => $GLOBALS['wgModernTimelineTickWidth'] |
67
|
|
|
]; |
68
|
|
|
|
69
|
23 |
|
$definitions[self::PARAM_START_SLIDE] = [ |
70
|
23 |
|
'type' => ParameterTypes::INTEGER, |
71
|
23 |
|
'default' => $GLOBALS['wgModernTimelineStartSlide'], |
72
|
23 |
|
'lowerbound' => 1 |
73
|
|
|
]; |
74
|
|
|
|
75
|
23 |
|
$definitions[self::PARAM_START_AT_END] = [ |
76
|
23 |
|
'type' => ParameterTypes::BOOLEAN, |
77
|
23 |
|
'default' => $GLOBALS['wgModernTimelineStartAtEnd'] |
78
|
|
|
]; |
79
|
|
|
|
80
|
23 |
|
$definitions[self::PARAM_TRANSITION_DURATION] = [ |
81
|
23 |
|
'type' => ParameterTypes::INTEGER, |
82
|
23 |
|
'aliases' => 'duration', |
83
|
23 |
|
'default' => $GLOBALS['wgModernTimelineTransitionDuration'], |
84
|
23 |
|
'lowerbound' => 1 |
85
|
|
|
]; |
86
|
|
|
|
87
|
23 |
|
$definitions[self::PARAM_NAV_HEIGHT] = [ |
88
|
23 |
|
'type' => ParameterTypes::DIMENSION, |
89
|
|
|
'units' => [ 'px', '%' ], |
90
|
23 |
|
'default' => $GLOBALS['wgModernTimelineNavHeight'], |
91
|
|
|
]; |
92
|
|
|
|
93
|
23 |
|
$definitions[self::PARAM_TEMPLATE] = [ |
94
|
23 |
|
'type' => ParameterTypes::STRING, |
95
|
23 |
|
'default' => $GLOBALS['wgModernTimelineTemplate'] |
96
|
|
|
]; |
97
|
|
|
|
98
|
23 |
|
$definitions[self::PARAM_IMAGE] = [ |
99
|
23 |
|
'type' => ParameterTypes::STRING, |
100
|
23 |
|
'default' => $GLOBALS['wgModernTimelineImageProperty'], |
101
|
|
|
'aliases' => [ 'imageproperty', 'image' ], |
102
|
|
|
]; |
103
|
|
|
|
104
|
23 |
|
foreach ( $definitions as $name => $definition ) { |
105
|
23 |
|
$definitions[$name]['message'] = 'modern-timeline-param-' . str_replace( ' ', '-', $name ); |
106
|
|
|
|
107
|
23 |
|
if ( strpos( $name, ' ' ) !== false ) { |
108
|
23 |
|
$definitions[$name]['aliases'] = array_merge( |
109
|
23 |
|
array_key_exists( 'aliases', $definitions[$name] ) ? (array)$definitions[$name]['aliases'] : [], |
110
|
23 |
|
[ str_replace( ' ', '', $name ) ] |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
23 |
|
return $definitions; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param array $parameters |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
7 |
|
public static function processedParamsToJson( array $parameters ): array { |
123
|
|
|
$json = [ |
124
|
7 |
|
'hash_bookmark' => $parameters[self::PARAM_BOOKMARK], |
125
|
7 |
|
'default_bg_color' => $parameters[self::PARAM_BACKGROUND], |
126
|
7 |
|
'scale_factor' => $parameters[self::PARAM_SCALE_FACTOR], |
127
|
7 |
|
'timenav_position' => $parameters[self::PARAM_POSITION], |
128
|
7 |
|
'optimal_tick_width' => $parameters[self::PARAM_TICK_WIDTH], |
129
|
7 |
|
'start_at_slide' => self::getStartAtSlide( $parameters ), |
130
|
7 |
|
'start_at_end' => $parameters[self::PARAM_START_AT_END], |
131
|
7 |
|
'duration' => $parameters[self::PARAM_TRANSITION_DURATION], |
132
|
|
|
]; |
133
|
|
|
|
134
|
7 |
|
$height = $parameters[self::PARAM_NAV_HEIGHT]; |
135
|
|
|
|
136
|
7 |
|
if ( strpos( $height, '%' ) === false ) { |
137
|
6 |
|
$json['timenav_height'] = (int)substr( $height, 0, -2 ); |
138
|
|
|
} |
139
|
|
|
else { |
140
|
1 |
|
$json['timenav_height_percentage'] = (int)substr( $height, 0, -1 ); |
141
|
|
|
} |
142
|
|
|
|
143
|
7 |
|
return $json; |
144
|
|
|
} |
145
|
|
|
|
146
|
7 |
|
private static function getStartAtSlide( array $parameters ): int { |
147
|
7 |
|
return $parameters[self::PARAM_START_SLIDE] - 1; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
|