forked from XoopsModules25x/modulebuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreadcrumb.php
More file actions
81 lines (69 loc) · 2.17 KB
/
Breadcrumb.php
File metadata and controls
81 lines (69 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php declare(strict_types=1);
namespace XoopsModules\Modulebuilder\Common;
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* Breadcrumb Class
*
* @copyright XOOPS Project (https://xoops.org)
* @license https://www.fsf.org/copyleft/gpl.html GNU public license
* @author lucio <lucio.rota@gmail.com>
* @package Modulebuilder
*
* Example:
* $breadcrumb = new Common\Breadcrumb();
* $breadcrumb->addLink( 'bread 1', 'index1.php' );
* $breadcrumb->addLink( 'bread 2', '' );
* $breadcrumb->addLink( 'bread 3', 'index3.php' );
* echo $breadcrumb->render();
*/
use XoopsModules\Modulebuilder;
use XoopsModules\Modulebuilder\Common;
\defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined');
/**
* Class Breadcrumb
*/
class Breadcrumb
{
public string $dirname;
private array $bread = [];
public function __construct()
{
$this->dirname = \basename(\dirname(__DIR__, 2));
}
/**
* Add link to breadcrumb
*
* @param string $title
* @param string $link
*/
public function addLink(string $title = '', string $link = ''): void
{
$this->bread[] = [
'link' => $link,
'title' => $title,
];
}
/**
* Render BreadCrumb
*/
public function render()
{
if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
require $GLOBALS['xoops']->path('class/theme.php');
$GLOBALS['xoTheme'] = new \xos_opal_Theme();
}
require $GLOBALS['xoops']->path('class/template.php');
$breadcrumbTpl = new \XoopsTpl();
$breadcrumbTpl->assign('breadcrumb', $this->bread);
$html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
unset($breadcrumbTpl);
return $html;
}
}