icon = $info['icon']; if (!array_key_exists('title', $info)) throw new Exception('Property title missing'); else $this->title = $info['title']; if (!array_key_exists('link', $info) && !array_key_exists('function', $info)) throw new Exception('Property link and function missing'); if (array_key_exists('id', $info)) $this->id = $info['id']; if (array_key_exists('link', $info)) $this->link = $info['link']; if (array_key_exists('function', $info)) $this->function = $info['function']; if (array_key_exists('anchor', $info)) $this->anchor = $info['anchor']; } public function toString() { if ($this->anchor) { $imgattr = array('border="0"'); $attr = array(); if ($this->id) $attr[] = sprintf('id="%s"', $this->id); if ($this->title) $attr[] = sprintf('title="%s"', $this->title); if ($this->icon) $imgattr[] = sprintf('src="%s"', $this->icon); if ($this->function) { $attr[] = 'href="#"'; $attr[] = sprintf('onclick="return %s(event)"', $this->function); } elseif ($this->link) $attr[] = sprintf('href="%s"', $this->link); $code = sprintf('', implode(' ', $attr), implode(' ', $imgattr)); } else { $attr = array('border="0"'); if ($this->id) $attr[] = sprintf('id="%s"', $this->id); if ($this->title) $attr[] = sprintf('title="%s"', $this->title); if ($this->icon) $attr[] = sprintf('src="%s"', $this->icon); if ($this->function) $attr[] = sprintf('onclick="return %s(event)"', $this->function); elseif ($this->link) $attr[] = sprintf("onclick=\"function(){ window.href.location = '%s'; }\"", $this->link); $code = sprintf('', implode(' ', $attr)); } return $code; } }