Passed
Pull Request — master (#5)
by Michael
02:33
created

Breadcrumb::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmdownloads\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
/**
15
 * Breadcrumb Class
16
 *
17
 * @copyright   XOOPS Project (https://xoops.org)
18
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
19
 * @author      lucio <[email protected]>
20
 * @package     pedigree
21
 * @since       3.23
22
 * @version     $Id: breadcrumb.php 12865 2014-11-22 07:03:35Z beckmi $
23
 *
24
 * Example:
25
 * $breadcrumb = new \Breadcrumb();
26
 * $breadcrumb->addLink( 'bread 1', 'index1.php' );
27
 * $breadcrumb->addLink( 'bread 2', '' );
28
 * $breadcrumb->addLink( 'bread 3', 'index3.php' );
29
 * echo $breadcrumb->render();
30
 */
31
defined('XOOPS_ROOT_PATH') || die('Restricted access');
32
33
/**
34
 * Class Breadcrumb
35
 */
36
class Breadcrumb
37
{
38
    public  $dirname;
39
    private $bread = [];
40
41
    public function __construct()
42
    {
43
        $this->dirname = basename(dirname(dirname(__DIR__)));
44
    }
45
46
    /**
47
     * Add link to breadcrumb
48
     *
49
     * @param string $title
50
     * @param string $link
51
     */
52
    public function addLink($title = '', $link = '')
53
    {
54
        $this->bread[] = [
55
            'link'  => $link,
56
            'title' => $title,
57
        ];
58
    }
59
60
    /**
61
     * Render BreadCrumb
62
     */
63
    public function render()
64
    {
65
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
66
            require_once $GLOBALS['xoops']->path('class/theme.php');
67
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
68
        }
69
70
        require_once $GLOBALS['xoops']->path('class/template.php');
71
        $breadcrumbTpl = new \XoopsTpl();
72
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
73
        $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
74
        unset($breadcrumbTpl);
75
76
        return $html;
77
    }
78
}
79