1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xnewsletter\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 xnewsletter |
21
|
|
|
* |
22
|
|
|
* Example: |
23
|
|
|
* $breadcrumb = new Common\Breadcrumb(); |
24
|
|
|
* $breadcrumb->addLink( 'bread 1', 'index1.php' ); |
25
|
|
|
* $breadcrumb->addLink( 'bread 2', '' ); |
26
|
|
|
* $breadcrumb->addLink( 'bread 3', 'index3.php' ); |
27
|
|
|
* echo $breadcrumb->render(); |
28
|
|
|
*/ |
29
|
|
|
use XoopsModules\Xnewsletter; |
30
|
|
|
use XoopsModules\Xnewsletter\Common; |
31
|
|
|
|
32
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined'); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class Breadcrumb |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
class Breadcrumb |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
public $dirname; |
40
|
|
|
private $bread = []; |
41
|
|
|
|
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
$this->dirname = basename(dirname(dirname(__DIR__))); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Add link to breadcrumb |
49
|
|
|
* |
50
|
|
|
* @param string $title |
51
|
|
|
* @param string $link |
52
|
|
|
*/ |
53
|
|
|
public function addLink($title = '', $link = '') |
54
|
|
|
{ |
55
|
|
|
$this->bread[] = [ |
56
|
|
|
'link' => $link, |
57
|
|
|
'title' => $title, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Render BreadCrumb |
63
|
|
|
*/ |
64
|
|
|
public function render() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
67
|
|
|
require $GLOBALS['xoops']->path('class/theme.php'); |
68
|
|
|
$GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
require $GLOBALS['xoops']->path('class/template.php'); |
72
|
|
|
$breadcrumbTpl = new \XoopsTpl(); |
73
|
|
|
$breadcrumbTpl->assign('breadcrumb', $this->bread); |
74
|
|
|
$html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
75
|
|
|
unset($breadcrumbTpl); |
76
|
|
|
|
77
|
|
|
return $html; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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.