Completed
Push — master ( 592643...f454c2 )
by Michael
03:05 queued 01:21
created

class/Breadcrumb.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace XoopsModules\Xnewsletter;
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
/**
16
 * Breadcrumb Class
17
 *
18
 * @copyright   XOOPS Project (https://xoops.org)
19
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @author      lucio <[email protected]>
21
 * @package     xnewsletter
22
 * @since       1.3
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 View Code Duplication
class Breadcrumb
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
{
33
    public  $dirname;
34
    private $bread = [];
35
36
    public function __construct()
37
    {
38
        $this->dirname = basename(dirname(__DIR__));
39
    }
40
41
    /**
42
     * Add link to breadcrumb
43
     *
44
     * @param string $title
45
     * @param string $link
46
     */
47
    public function addLink($title = '', $link = '')
48
    {
49
        $this->bread[] = [
50
            'link'  => $link,
51
            'title' => $title,
52
        ];
53
    }
54
55
    /**
56
     * Render xnewsletter BreadCrumb
57
     */
58
    public function render()
59
    {
60
        if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) {
61
            require_once $GLOBALS['xoops']->path('/class/theme.php');
62
            $GLOBALS['xoTheme'] = new \xos_opal_Theme();
63
        }
64
65
        require_once $GLOBALS['xoops']->path('class/template.php');
66
        $breadcrumbTpl = new \XoopsTpl();
67
        $breadcrumbTpl->assign('breadcrumb', $this->bread);
68
        $html = $breadcrumbTpl->fetch("db:{$this->dirname}_common_breadcrumb.tpl");
69
        unset($breadcrumbTpl);
70
71
        return $html;
72
    }
73
}
74