1
|
|
|
<?php namespace Xoopsmodules\xsitemap\common; |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
/** |
12
|
|
|
* Breadcrumb Class |
13
|
|
|
* |
14
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
15
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
16
|
|
|
* @author lucio <[email protected]> |
17
|
|
|
* @package pedigree |
18
|
|
|
* @since 3.23 |
19
|
|
|
* @version $Id: breadcrumb.php 12865 2014-11-22 07:03:35Z beckmi $ |
20
|
|
|
* |
21
|
|
|
* Example: |
22
|
|
|
* $breadcrumb = new PedigreeBreadcrumb(); |
23
|
|
|
* $breadcrumb->addLink( 'bread 1', 'index1.php' ); |
24
|
|
|
* $breadcrumb->addLink( 'bread 2', '' ); |
25
|
|
|
* $breadcrumb->addLink( 'bread 3', 'index3.php' ); |
26
|
|
|
* echo $breadcrumb->render(); |
27
|
|
|
*/ |
28
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS Root Path not defined'); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class PedigreeBreadcrumb |
32
|
|
|
*/ |
33
|
|
|
class Breadcrumb |
34
|
|
|
{ |
35
|
|
|
public $dirname; |
36
|
|
|
private $bread = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
*/ |
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
$this->dirname = basename(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 Pedigree BreadCrumb |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
|
public function render() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
67
|
|
|
require_once $GLOBALS['xoops']->path('class/theme.php'); |
68
|
|
|
$GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
require_once $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
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.