Metadata   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 137
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
B generate() 0 33 3
A names() 0 19 2
A plugins() 0 23 3
A themes() 0 23 3
1
<?php
2
3
/**
4
 * Collects the important data from all translations for a central registry
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Translation
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\translation;
17
18
/**
19
 * Collects the important data from all translations for a central registry
20
 *
21
 * @category  Core
22
 * @package   Translation
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 = 'language';
35
36
    /**
37
     * Generate registry from XML files
38
     *
39
     * @return array
40
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
41
42
    protected function generate()
43
    {
44
        // Try to load metadata from cache
45
        $key = 'metadata_' . $this->driver;
46
        $reg = $this->cache->load($key);
47
48
        // If cache loading fails load it and create cache file
49
        if ($reg == false) {
50
51
            // Get a directory listing of all default languages
52
            $origin = $this->path . 'csphere/plugins/default/languages';
53
            $files  = \csphere\core\files\File::search($origin);
54
55
            // Load xml content into an array
56
            $xml = $this->loader->load('xml', 'language');
57
            $reg = [];
58
59
            foreach ($files AS $file) {
60
61
                $lang   = explode('.xml', $file);
62
                $source = $xml->source('plugin', 'default', $lang[0]);
63
64
                // Definitions are just wasting space here
65
                unset($source['definitions']);
66
67
                $reg[$lang[0]] = $source;
68
            }
69
70
            $this->cache->save($key, $reg);
71
        }
72
73
        return $reg;
74
    }
75
76
    /**
77
     * List all language names with their short tag
78
     *
79
     * @return array
80
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
81
82
    public function names()
83
    {
84
        // Create a list of languages
85
        $reg   = $this->generate();
86
        $names = [];
87
88
        foreach ($reg AS $short => $info) {
89
90
            $names[$info['name']] = ['name'     => $info['name'],
91
                                     'short'    => $short,
92
                                     'icon_url' => $info['icon']['url']];
93
        }
94
95
        ksort($names);
96
97
        $names = array_values($names);
98
99
        return $names;
100
    }
101
102
    /**
103
     * List of all plugins with their translation status
104
     *
105
     * @param string $lang Language short handle, e.g. en
106
     *
107
     * @return array
108
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
109
110
    public function plugins($lang)
111
    {
112
        // Get plugin metadata
113
        $meta = new \csphere\core\plugins\Metadata();
114
115
        $plugins = $meta->details();
116
117
        // Add translation status to each entry
118
        $result = [];
119
120
        foreach ($plugins AS $plugin) {
121
122
            $origin = $this->path . 'csphere/plugins/'
123
                    . $plugin['short'] . '/languages/'
124
                    . $lang . '.xml';
125
126
            $plugin['exists'] = file_exists($origin) ? 'yes' : '';
127
128
            $result[] = $plugin;
129
        }
130
131
        return $result;
132
    }
133
134
    /**
135
     * List of all themes with their translation status
136
     *
137
     * @param string $lang Language short handle, e.g. en
138
     *
139
     * @return array
140
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
141
142
    public function themes($lang)
143
    {
144
        // Get plugin metadata
145
        $meta = new \csphere\core\themes\Metadata();
146
147
        $themes = $meta->details();
148
149
        // Add translation status to each entry
150
        $result = [];
151
152
        foreach ($themes AS $theme) {
153
154
            $origin = $this->path . 'csphere/themes/'
155
                    . $theme['short'] . '/languages/'
156
                    . $lang . '.xml';
157
158
            $theme['exists'] = file_exists($origin) ? 'yes' : '';
159
160
            $result[] = $theme;
161
        }
162
163
        return $result;
164
    }
165
}
166