mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00

- add podcast sidebar navigation - add podcast dashboard with latest episodes - add pagination to podcast episodes - add components helper to reuse ui components (button, data_table, etc.) - enhance podcast and episode forms by splitting them into form sections - add hint tooltips to podcast and episode forms - transform radio inputs as buttons for better ux - replace explicit field by parental_advisory - replace author field by publisher - add podcasts_categories table to set multiple categories - use choices.js to enhance multiselect fields - update Language files - update js dependencies to latest versions closes #31, #9
107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Generates and renders a breadcrumb based on the current url segments
|
|
*
|
|
* @copyright 2020 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Libraries;
|
|
|
|
class Breadcrumb
|
|
{
|
|
/**
|
|
* List of breadcrumb links.
|
|
*
|
|
* @var array
|
|
* $links = [
|
|
* 'text' => (string) the anchor text,
|
|
* 'href' => (string) the anchor href,
|
|
* ]
|
|
*/
|
|
protected $links = [];
|
|
|
|
/**
|
|
* Initializes the Breadcrumb object using the segments from
|
|
* current_url by populating the $links property with text and href data
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$uri = '';
|
|
foreach (current_url(true)->getSegments() as $segment) {
|
|
$uri .= '/' . $segment;
|
|
array_push($this->links, [
|
|
'text' => is_numeric($segment)
|
|
? $segment
|
|
: lang('Breadcrumb.' . $segment),
|
|
'href' => base_url($uri),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Replaces all numeric text in breadcrumb's $link property
|
|
* with new params at same position
|
|
*
|
|
* Given a breadcrumb with numeric params, this function
|
|
* replaces them with the values provided in $newParams
|
|
*
|
|
* Example with `Home / podcasts / 1 / episodes / 1`
|
|
*
|
|
* $newParams = [
|
|
* 0 => 'foo',
|
|
* 1 => 'bar'
|
|
* ]
|
|
* replaceParams($newParams);
|
|
*
|
|
* The breadcrumb is now `Home / podcasts / foo / episodes / bar`
|
|
*
|
|
* @param array $newParams
|
|
*/
|
|
public function replaceParams($newParams)
|
|
{
|
|
foreach ($this->links as $key => $link) {
|
|
if (is_numeric($link['text'])) {
|
|
$this->links[$key]['text'] = $newParams[0];
|
|
array_shift($newParams);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Renders the breadcrumb object as an accessible html breadcrumb nav
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render($class = null)
|
|
{
|
|
$listItems = '';
|
|
$keys = array_keys($this->links);
|
|
foreach ($this->links as $key => $link) {
|
|
if (end($keys) == $key) {
|
|
$listItem =
|
|
'<li class="breadcrumb-item active" aria-current="page">' .
|
|
$link['text'] .
|
|
'</li>';
|
|
} else {
|
|
$listItem =
|
|
'<li class="breadcrumb-item">' .
|
|
anchor($link['href'], $link['text']) .
|
|
'</li>';
|
|
}
|
|
|
|
$listItems .= $listItem;
|
|
}
|
|
|
|
return '<nav aria-label="' .
|
|
lang('Breadcrumb.label') .
|
|
'"><ol class="breadcrumb ' .
|
|
$class .
|
|
'">' .
|
|
$listItems .
|
|
'</ol></nav>';
|
|
}
|
|
}
|