Metadata::_genEntries()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 37
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 7
nop 2
dl 0
loc 37
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Collects the important data from all plugins for a central registry
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Plugins
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\plugins;
17
18
/**
19
 * Collects the important data from all plugins for a central registry
20
 *
21
 * @category  Core
22
 * @package   Plugins
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Metadata extends \csphere\core\xml\Metadata
30
{
31
    /**
32
     * Type of registry
33
     **/
34
    protected $driver = 'plugin';
35
36
    /**
37
     * Generate a list of plugins that contain the requested entry
38
     *
39
     * @param string $plugin Plugin name
40
     * @param string $action Action name
41
     *
42
     * @return array
43
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
44
45
    private function _genEntries($plugin, $action)
46
    {
47
        // Get registered plugins from cache
48
        $reg   = $this->generate();
49
        $names = [];
50
51
        // Create a list of plugins with name, dir and icon per element
52
        foreach ($reg AS $dir => $info) {
53
54
            // Not every plugin might contain entries
55
            $entries = [];
56
57
            if (isset($info['entries']['target'])) {
58
59
                $entries = $info['entries']['target'];
60
            }
61
62
            // Search for requested entry within plugin entries
63
            foreach ($entries AS $entry) {
64
65
                if ($plugin == $entry['plugin']
66
                    && $action == $entry['action']
67
                ) {
68
                    // Fetch plugin name from language file
69
                    $name = \csphere\core\translation\Fetch::key($dir, $dir);
70
71
                    $names[$name] = ['name' => $name,
72
                                     'dir'  => $dir,
73
                                     'icon' => $info['icon']['value']];
74
                }
75
            }
76
        }
77
78
        ksort($names);
79
80
        return $names;
81
    }
82
83
    /**
84
     * Lists all plugin names that contain the requested entry
85
     *
86
     * @param string $plugin Plugin name
87
     * @param string $action Action name
88
     *
89
     * @return array
90
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
91
92
    public function entries($plugin, $action)
93
    {
94
        // Try to load entries from cache
95
        $key = 'plugins_entries_' . $this->language . '_' . $plugin . '_' . $action;
96
        $ent = $this->cache->load($key);
97
98
        // If cache loading fails load it and create cache file
99
        if ($ent == false) {
100
101
            $ent = $this->_genEntries($plugin, $action);
102
103
            $this->cache->save($key, $ent);
104
        }
105
106
        return $ent;
107
    }
108
109
    /**
110
     * List all entries for startup files
111
     *
112
     * @return array
113
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
114
115
    public function startup()
116
    {
117
        // Create a list for each startup type
118
        $reg     = $this->generate();
119
        $startup = ['javascript' => [], 'stylesheet' => []];
120
121
        foreach ($reg AS $dir => $plugin) {
122
123
            // Check if plugin contains startup files
124
            if (isset($plugin['startup'])) {
125
126
                foreach ($plugin['startup'][0]['file'] AS $file) {
127
128
                    // Format array for later usage
129
                    $type = $file['type'];
130
                    $top  = ($file['top'] == 'true') ? true : false;
131
132
                    $startup[$type][] = ['plugin' => $dir,
133
                                         'top'    => $top,
134
                                         'file'   => $file['name']];
135
                }
136
            }
137
        }
138
139
        return $startup;
140
    }
141
142
    /**
143
     * Gets the Type of the current Template
144
     *
145
     * @param string $plugin Requested Plugin
146
     * @param string $action Requested Action
147
     *
148
     * @return string
149
     */
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
150
151
    public function templateType($plugin, $action)
152
    {
153
        $reg = $this->generate();
154
155
        if (isset($reg[$plugin]['routes'][$action])) {
156
            $type=$reg[$plugin]['routes'][$action];
157
        } else {
158
            $type="frontend";
159
        }
160
161
        return $type;
162
    }
163
}
164