| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters; |
| 4 |
|
| 5 |
/** |
| 6 |
* Presenter class for the URL list. |
| 7 |
*/ |
| 8 |
class Url_List_Presenter extends Abstract_Presenter { |
| 9 |
|
| 10 |
/** |
| 11 |
* A list of arrays containing titles and URLs. |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
private $links; |
| 16 |
|
| 17 |
/** |
| 18 |
* Classname for the URL list. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
private $class_name; |
| 23 |
|
| 24 |
/** |
| 25 |
* Url_List_Presenter constructor. |
| 26 |
* |
| 27 |
* @param array $links A list of arrays containing titles and urls. |
| 28 |
* @param string $class_name Classname for the url list. |
| 29 |
*/ |
| 30 |
public function __construct( $links, $class_name = 'yoast-url-list' ) { |
| 31 |
$this->links = $links; |
| 32 |
$this->class_name = $class_name; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Presents the URL list. |
| 37 |
* |
| 38 |
* @return string The URL list. |
| 39 |
*/ |
| 40 |
public function present() { |
| 41 |
$output = '<ul class="' . $this->class_name . '">'; |
| 42 |
foreach ( $this->links as $link ) { |
| 43 |
$output .= '<li><a href="' . $link['permalink'] . '">' . $link['title'] . '</a></li>'; |
| 44 |
} |
| 45 |
$output .= '</ul>'; |
| 46 |
return $output; |
| 47 |
} |
| 48 |
} |
| 49 |
|