ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLinkButton.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "Services/UIComponent/Button/classes/class.ilButtonBase.php";
5 
14 {
15  protected $url; // [string]
16  protected $target; // [string]
17 
18  public static function getInstance()
19  {
20  return new self(self::TYPE_LINK);
21  }
22 
23 
24  //
25  // properties
26  //
27 
33  public function setUrl($a_value)
34  {
35  $this->url = trim($a_value);
36  }
37 
43  public function getUrl()
44  {
45  return $this->url;
46  }
47 
53  public function setTarget($a_value)
54  {
55  $this->target = trim($a_value);
56  }
57 
63  public function getTarget()
64  {
65  return $this->target;
66  }
67 
68 
69  //
70  // render
71  //
72 
78  protected function renderCaption()
79  {
80  return '&nbsp;'.$this->getCaption().'&nbsp;';
81  }
82 
86  protected function renderAttributes(array $a_additional_attr = null)
87  {
88  if ('_blank' === $this->getTarget()) {
89  if (isset($a_additional_attr['rel'])) {
90  if (strpos($a_additional_attr['rel'], 'noopener') === false) {
91  $a_additional_attr['rel'] .= ' noopener';
92  }
93  } else {
94  $a_additional_attr['rel'] = 'noopener';
95  }
96  }
97 
98  return parent::renderAttributes($a_additional_attr);
99  }
100 
101  public function render()
102  {
103  $this->prepareRender();
104 
105  $attr = array();
106  $attr["href"] = $this->getUrl() ? $this->getUrl() : "#";
107  $attr["target"] = $this->getTarget();
108 
109  return '<a'.$this->renderAttributes($attr).'>'.
110  $this->renderCaption().'</a>';
111  }
112 }
renderAttributes(array $a_additional_attr=null)
setTarget($a_value)
Set target.
renderCaption()
Prepare caption for render.
prepareRender()
Prepare render.
setUrl($a_value)
Set URL.
Create styles array
The data for the language used.
getTarget()
Get target.