id = $ID; $this->type = $this->getType(); $this->params['do'] = $this->type; if(!actionOK($this->type)) throw new \RuntimeException("action disabled: {$this->type}"); } /** * Return this item's label * * When the label property was set, it is simply returned. Otherwise, the action's type * is used to look up the translation in the main language file and, if used, the replacement * is applied. * * @return string */ public function getLabel() { if($this->label !== '') return $this->label; /** @var array $lang */ global $lang; $label = $lang['btn_' . $this->type]; if(strpos($label, '%s')) { $label = sprintf($label, $this->replacement); } if($label === '') $label = '[' . $this->type . ']'; return $label; } /** * Return the link this item links to * * Basically runs wl() on $id and $params. However if the ID is a hash it is used directly * as the link * * Please note that the generated URL is *not* XML escaped. * * @see wl() * @return string */ public function getLink() { if($this->id[0] == '#') { return $this->id; } else { return wl($this->id, $this->params, false, '&'); } } /** * Convenience method to get the attributes for constructing an element * * @see buildAttributes() * @param string|false $classprefix create a class from type with this prefix, false for no class * @return array */ public function getLinkAttributes($classprefix = 'menuitem ') { $attr = array( 'href' => $this->getLink(), 'title' => $this->getLabel(), ); if($this->isNofollow()) $attr['rel'] = 'nofollow'; if($this->getAccesskey()) { $attr['accesskey'] = $this->getAccesskey(); $attr['title'] .= ' [' . $this->getAccesskey() . ']'; } if($classprefix !== false) $attr['class'] = $classprefix . $this->getType(); return $attr; } /** * Convenience method to create a full element * * Wraps around the label and SVG image * * @param string|false $classprefix create a class from type with this prefix, false for no class * @param bool $svg add SVG icon to the link * @return string */ public function asHtmlLink($classprefix = 'menuitem ', $svg = true) { $attr = buildAttributes($this->getLinkAttributes($classprefix)); $html = ""; if($svg) { $html .= '' . hsc($this->getLabel()) . ''; $html .= inlineSVG($this->getSvg()); } else { $html .= hsc($this->getLabel()); } $html .= ""; return $html; } /** * Should this item be shown in the given context * * @param int $ctx the current context * @return bool */ public function visibleInContext($ctx) { return (bool) ($ctx & $this->context); } /** * @return string the name of this item */ public function getType() { if($this->type === '') { $this->type = strtolower(substr(strrchr(get_class($this), '\\'), 1)); } return $this->type; } /** * @return string */ public function getAccesskey() { return $this->accesskey; } /** * @return array */ public function getParams() { return $this->params; } /** * @return bool */ public function isNofollow() { return $this->nofollow; } /** * @return string */ public function getSvg() { return $this->svg; } /** * Return this Item's settings as an array as used in tpl_get_action() * * @return array */ public function getLegacyData() { return array( 'accesskey' => $this->accesskey ? $this->accesskey : null, 'type' => $this->type, 'id' => $this->id, 'method' => $this->method, 'params' => $this->params, 'nofollow' => $this->nofollow, 'replacement' => $this->replacement ); } }