Completed
Push — master ( 0881bb...3a6ebc )
by Michael
04:47
created

AltsysBreadcrumbs::__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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
// singleton for xoops_breadcrumbs
4
class AltsysBreadcrumbs
5
{
6
7
    public $paths = array() ;
8
9
    public function __construct()
10
    {
11
    }
12
//HACK by domifara for php5.3+
13
//function &getInstance()
14
public static function &getInstance()
15
{
16
    static $instance ;
17
    if (! isset($instance)) {
18
        $instance = new AltsysBreadcrumbs() ;
19
    }
20
    return $instance ;
21
}
22
23
    public function getXoopsBreadcrumbs()
24
    {
25
        $ret = array() ;
26
        foreach ($this->paths as $val) {
27
            // delayed language constant
28
        if (substr($val['name'], 0, 1) == '_' && defined($val['name'])) {
29
            $ret[] = array(
30
                'url' => $val['url'] ,
31
                'name' => constant($val['name'])
32
            ) ;
33
        } else {
34
            $ret[] = $val ;
35
        }
36
        }
37
        unset($ret[count($ret) - 1 ]['url']) ;
38
        return $ret ;
39
    }
40
41
// all data should be escaped
42
public function appendPath($url_or_path, $name = '...')
43
{
44
    if (is_array($url_or_path)) {
45
        if (empty($url_or_path['name'])) {
46
            // multiple paths
47
            $this->paths = array_merge($this->paths, $url_or_path) ;
48
        } else {
49
            // array format (just a path)
50
            $this->paths[] = $url_or_path ;
51
        }
52
    } else {
53
        // separate format
54
        $this->paths[] = array( 'url' => $url_or_path , 'name' => $name ) ;
55
    }
56
}
57
58
    public function hasPaths()
59
    {
60
        return ! empty($this->paths) ;
61
    }
62
}
63