| @@ -7,8 +7,15 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | class Url_List_Presenter extends Abstract_Presenter { |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | + * If the url should be target blank. | |
| 12 | + * | |
| 13 | + * @var bool | |
| 14 | + */ | |
| 15 | + private $target_blank; | |
| 16 | + | |
| 17 | + /** | |
| 11 | 18 | * A list of arrays containing titles and URLs. |
| 12 | 19 | * |
| 13 | 20 | * @var array |
| 14 | 21 | */ |
| @@ -23,14 +30,16 @@ | ||
| 23 | 30 | |
| 24 | 31 | /** |
| 25 | 32 | * Url_List_Presenter constructor. |
| 26 | 33 | * |
| 27 | - * @param array $links A list of arrays containing titles and urls. | |
| 28 | - * @param string $class_name Classname for the url list. | |
| 34 | + * @param array $links A list of arrays containing titles and urls. | |
| 35 | + * @param string $class_name Classname for the url list. | |
| 36 | + * @param bool $target_blank If the url should be target blank. | |
| 29 | 37 | */ |
| 30 | - public function __construct( $links, $class_name = 'yoast-url-list' ) { | |
| 31 | - $this->links = $links; | |
| 32 | - $this->class_name = $class_name; | |
| 38 | + public function __construct( $links, $class_name = 'yoast-url-list', $target_blank = false ) { | |
| 39 | + $this->links = $links; | |
| 40 | + $this->class_name = $class_name; | |
| 41 | + $this->target_blank = $target_blank; | |
| 33 | 42 | } |
| 34 | 43 | |
| 35 | 44 | /** |
| 36 | 45 | * Presents the URL list. |
| @@ -39,10 +48,15 @@ | ||
| 39 | 48 | */ |
| 40 | 49 | public function present() { |
| 41 | 50 | $output = '<ul class="' . $this->class_name . '">'; |
| 42 | 51 | foreach ( $this->links as $link ) { |
| 43 | - $output .= '<li><a href="' . $link['permalink'] . '">' . $link['title'] . '</a></li>'; | |
| 52 | + $output .= '<li><a'; | |
| 53 | + if ( $this->target_blank ) { | |
| 54 | + $output .= ' target = "_blank"'; | |
| 55 | + } | |
| 56 | + $output .= ' href="' . \esc_url( $link['permalink'] ) . '">' . \esc_html( $link['title'] ) . '</a></li>'; | |
| 44 | 57 | } |
| 45 | 58 | $output .= '</ul>'; |
| 59 | + | |
| 46 | 60 | return $output; |
| 47 | 61 | } |
| 48 | 62 | } |