1 | <?php |
||
20 | abstract class AbstractItem { |
||
21 | |||
22 | /** menu item is to be shown on desktop screens only */ |
||
23 | const CTX_DESKTOP = 1; |
||
24 | /** menu item is to be shown on mobile screens only */ |
||
25 | const CTX_MOBILE = 2; |
||
26 | /** menu item is to be shown in all contexts */ |
||
27 | const CTX_ALL = 3; |
||
28 | |||
29 | /** @var string name of the action, usually the lowercase class name */ |
||
30 | protected $type = ''; |
||
31 | /** @var string optional keyboard shortcut */ |
||
32 | protected $accesskey = ''; |
||
33 | /** @var string the page id this action links to */ |
||
34 | protected $id = ''; |
||
35 | /** @var string the method to be used when this action is used in a form */ |
||
36 | protected $method = 'get'; |
||
37 | /** @var array parameters for the action (should contain the do parameter) */ |
||
38 | protected $params = array(); |
||
39 | /** @var bool when true, a rel=nofollow should be used */ |
||
40 | protected $nofollow = true; |
||
41 | /** @var string this item's label may contain a placeholder, which is replaced with this */ |
||
42 | protected $replacement = ''; |
||
43 | /** @var string the full path to the SVG icon of this menu item */ |
||
44 | protected $svg = DOKU_INC . 'lib/images/menu/00-default_checkbox-blank-circle-outline.svg'; |
||
45 | /** @var string can be set to overwrite the default lookup in $lang.btn_* */ |
||
46 | protected $label = ''; |
||
47 | /** @var string the tooltip title, defaults to $label */ |
||
48 | protected $title = ''; |
||
49 | /** @var int the context this titme is shown in */ |
||
50 | protected $context = self::CTX_ALL; |
||
51 | |||
52 | /** |
||
53 | * AbstractItem constructor. |
||
54 | * |
||
55 | * Sets the dynamic properties |
||
56 | * |
||
57 | * Children should always call the parent constructor! |
||
58 | * |
||
59 | * @throws \RuntimeException when the action is disabled |
||
60 | */ |
||
61 | public function __construct() { |
||
69 | |||
70 | /** |
||
71 | * Return this item's label |
||
72 | * |
||
73 | * When the label property was set, it is simply returned. Otherwise, the action's type |
||
74 | * is used to look up the translation in the main language file and, if used, the replacement |
||
75 | * is applied. |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getLabel() { |
||
91 | |||
92 | /** |
||
93 | * Return this item's title |
||
94 | * |
||
95 | * This title should be used to display a tooltip (using the HTML title attribute). If |
||
96 | * a title property was not explicitly set, the label will be returned. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public function getTitle() { |
||
104 | |||
105 | /** |
||
106 | * Return the link this item links to |
||
107 | * |
||
108 | * Basically runs wl() on $id and $params. However if the ID is a hash it is used directly |
||
109 | * as the link |
||
110 | * |
||
111 | * Please note that the generated URL is *not* XML escaped. |
||
112 | * |
||
113 | * @see wl() |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getLink() { |
||
123 | |||
124 | /** |
||
125 | * Convenience method to get the attributes for constructing an <a> element |
||
126 | * |
||
127 | * @see buildAttributes() |
||
128 | * @param string|false $classprefix create a class from type with this prefix, false for no class |
||
129 | * @return array |
||
130 | */ |
||
131 | public function getLinkAttributes($classprefix = 'menuitem ') { |
||
145 | |||
146 | /** |
||
147 | * Convenience method to create a full <a> element |
||
148 | * |
||
149 | * Wraps around the label and SVG image |
||
150 | * |
||
151 | * @param string|false $classprefix create a class from type with this prefix, false for no class |
||
152 | * @param bool $svg add SVG icon to the link |
||
153 | * @return string |
||
154 | */ |
||
155 | public function asHtmlLink($classprefix = 'menuitem ', $svg = true) { |
||
168 | |||
169 | /** |
||
170 | * Convenience method to create a <button> element inside it's own form element |
||
171 | * |
||
172 | * Uses html_btn() |
||
173 | * |
||
174 | * @todo this does currently not support the SVG icon |
||
175 | * @return string |
||
176 | */ |
||
177 | public function asHtmlButton() { |
||
188 | |||
189 | /** |
||
190 | * Should this item be shown in the given context |
||
191 | * |
||
192 | * @param int $ctx the current context |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function visibleInContext($ctx) { |
||
198 | |||
199 | /** |
||
200 | * @return string the name of this item |
||
201 | */ |
||
202 | public function getType() { |
||
208 | |||
209 | /** |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getAccesskey() { |
||
215 | |||
216 | /** |
||
217 | * @return array |
||
218 | */ |
||
219 | public function getParams() { |
||
222 | |||
223 | /** |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function isNofollow() { |
||
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getSvg() { |
||
236 | |||
237 | /** |
||
238 | * Return this Item's settings as an array as used in tpl_get_action() |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | public function getLegacyData() { |
||
253 | } |
||
254 |