@@ -33,245 +33,245 @@ |
||
| 33 | 33 | use OCP\ICache; |
| 34 | 34 | |
| 35 | 35 | class InfoParser { |
| 36 | - /** @var \OCP\ICache|null */ |
|
| 37 | - private $cache; |
|
| 36 | + /** @var \OCP\ICache|null */ |
|
| 37 | + private $cache; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param ICache|null $cache |
|
| 41 | - */ |
|
| 42 | - public function __construct(ICache $cache = null) { |
|
| 43 | - $this->cache = $cache; |
|
| 44 | - } |
|
| 39 | + /** |
|
| 40 | + * @param ICache|null $cache |
|
| 41 | + */ |
|
| 42 | + public function __construct(ICache $cache = null) { |
|
| 43 | + $this->cache = $cache; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param string $file the xml file to be loaded |
|
| 48 | - * @return null|array where null is an indicator for an error |
|
| 49 | - */ |
|
| 50 | - public function parse($file) { |
|
| 51 | - if (!file_exists($file)) { |
|
| 52 | - return null; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * @param string $file the xml file to be loaded |
|
| 48 | + * @return null|array where null is an indicator for an error |
|
| 49 | + */ |
|
| 50 | + public function parse($file) { |
|
| 51 | + if (!file_exists($file)) { |
|
| 52 | + return null; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - if ($this->cache !== null) { |
|
| 56 | - $fileCacheKey = $file . filemtime($file); |
|
| 57 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 58 | - return json_decode($cachedValue, true); |
|
| 59 | - } |
|
| 60 | - } |
|
| 55 | + if ($this->cache !== null) { |
|
| 56 | + $fileCacheKey = $file . filemtime($file); |
|
| 57 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
| 58 | + return json_decode($cachedValue, true); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - libxml_use_internal_errors(true); |
|
| 63 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 64 | - $xml = simplexml_load_file($file); |
|
| 62 | + libxml_use_internal_errors(true); |
|
| 63 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 64 | + $xml = simplexml_load_file($file); |
|
| 65 | 65 | |
| 66 | - libxml_disable_entity_loader($loadEntities); |
|
| 67 | - if ($xml === false) { |
|
| 68 | - libxml_clear_errors(); |
|
| 69 | - return null; |
|
| 70 | - } |
|
| 71 | - $array = $this->xmlToArray($xml); |
|
| 66 | + libxml_disable_entity_loader($loadEntities); |
|
| 67 | + if ($xml === false) { |
|
| 68 | + libxml_clear_errors(); |
|
| 69 | + return null; |
|
| 70 | + } |
|
| 71 | + $array = $this->xmlToArray($xml); |
|
| 72 | 72 | |
| 73 | - if (is_null($array)) { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 73 | + if (is_null($array)) { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - if (!array_key_exists('info', $array)) { |
|
| 78 | - $array['info'] = []; |
|
| 79 | - } |
|
| 80 | - if (!array_key_exists('remote', $array)) { |
|
| 81 | - $array['remote'] = []; |
|
| 82 | - } |
|
| 83 | - if (!array_key_exists('public', $array)) { |
|
| 84 | - $array['public'] = []; |
|
| 85 | - } |
|
| 86 | - if (!array_key_exists('types', $array)) { |
|
| 87 | - $array['types'] = []; |
|
| 88 | - } |
|
| 89 | - if (!array_key_exists('repair-steps', $array)) { |
|
| 90 | - $array['repair-steps'] = []; |
|
| 91 | - } |
|
| 92 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 93 | - $array['repair-steps']['install'] = []; |
|
| 94 | - } |
|
| 95 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 96 | - $array['repair-steps']['pre-migration'] = []; |
|
| 97 | - } |
|
| 98 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 99 | - $array['repair-steps']['post-migration'] = []; |
|
| 100 | - } |
|
| 101 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 102 | - $array['repair-steps']['live-migration'] = []; |
|
| 103 | - } |
|
| 104 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 105 | - $array['repair-steps']['uninstall'] = []; |
|
| 106 | - } |
|
| 107 | - if (!array_key_exists('background-jobs', $array)) { |
|
| 108 | - $array['background-jobs'] = []; |
|
| 109 | - } |
|
| 110 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
| 111 | - $array['two-factor-providers'] = []; |
|
| 112 | - } |
|
| 113 | - if (!array_key_exists('commands', $array)) { |
|
| 114 | - $array['commands'] = []; |
|
| 115 | - } |
|
| 116 | - if (!array_key_exists('activity', $array)) { |
|
| 117 | - $array['activity'] = []; |
|
| 118 | - } |
|
| 119 | - if (!array_key_exists('filters', $array['activity'])) { |
|
| 120 | - $array['activity']['filters'] = []; |
|
| 121 | - } |
|
| 122 | - if (!array_key_exists('settings', $array['activity'])) { |
|
| 123 | - $array['activity']['settings'] = []; |
|
| 124 | - } |
|
| 125 | - if (!array_key_exists('providers', $array['activity'])) { |
|
| 126 | - $array['activity']['providers'] = []; |
|
| 127 | - } |
|
| 128 | - if (!array_key_exists('settings', $array)) { |
|
| 129 | - $array['settings'] = []; |
|
| 130 | - } |
|
| 131 | - if (!array_key_exists('admin', $array['settings'])) { |
|
| 132 | - $array['settings']['admin'] = []; |
|
| 133 | - } |
|
| 134 | - if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 135 | - $array['settings']['admin-section'] = []; |
|
| 136 | - } |
|
| 137 | - if (!array_key_exists('personal', $array['settings'])) { |
|
| 138 | - $array['settings']['personal'] = []; |
|
| 139 | - } |
|
| 140 | - if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 141 | - $array['settings']['personal-section'] = []; |
|
| 142 | - } |
|
| 77 | + if (!array_key_exists('info', $array)) { |
|
| 78 | + $array['info'] = []; |
|
| 79 | + } |
|
| 80 | + if (!array_key_exists('remote', $array)) { |
|
| 81 | + $array['remote'] = []; |
|
| 82 | + } |
|
| 83 | + if (!array_key_exists('public', $array)) { |
|
| 84 | + $array['public'] = []; |
|
| 85 | + } |
|
| 86 | + if (!array_key_exists('types', $array)) { |
|
| 87 | + $array['types'] = []; |
|
| 88 | + } |
|
| 89 | + if (!array_key_exists('repair-steps', $array)) { |
|
| 90 | + $array['repair-steps'] = []; |
|
| 91 | + } |
|
| 92 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
| 93 | + $array['repair-steps']['install'] = []; |
|
| 94 | + } |
|
| 95 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
| 96 | + $array['repair-steps']['pre-migration'] = []; |
|
| 97 | + } |
|
| 98 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
| 99 | + $array['repair-steps']['post-migration'] = []; |
|
| 100 | + } |
|
| 101 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
| 102 | + $array['repair-steps']['live-migration'] = []; |
|
| 103 | + } |
|
| 104 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
| 105 | + $array['repair-steps']['uninstall'] = []; |
|
| 106 | + } |
|
| 107 | + if (!array_key_exists('background-jobs', $array)) { |
|
| 108 | + $array['background-jobs'] = []; |
|
| 109 | + } |
|
| 110 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
| 111 | + $array['two-factor-providers'] = []; |
|
| 112 | + } |
|
| 113 | + if (!array_key_exists('commands', $array)) { |
|
| 114 | + $array['commands'] = []; |
|
| 115 | + } |
|
| 116 | + if (!array_key_exists('activity', $array)) { |
|
| 117 | + $array['activity'] = []; |
|
| 118 | + } |
|
| 119 | + if (!array_key_exists('filters', $array['activity'])) { |
|
| 120 | + $array['activity']['filters'] = []; |
|
| 121 | + } |
|
| 122 | + if (!array_key_exists('settings', $array['activity'])) { |
|
| 123 | + $array['activity']['settings'] = []; |
|
| 124 | + } |
|
| 125 | + if (!array_key_exists('providers', $array['activity'])) { |
|
| 126 | + $array['activity']['providers'] = []; |
|
| 127 | + } |
|
| 128 | + if (!array_key_exists('settings', $array)) { |
|
| 129 | + $array['settings'] = []; |
|
| 130 | + } |
|
| 131 | + if (!array_key_exists('admin', $array['settings'])) { |
|
| 132 | + $array['settings']['admin'] = []; |
|
| 133 | + } |
|
| 134 | + if (!array_key_exists('admin-section', $array['settings'])) { |
|
| 135 | + $array['settings']['admin-section'] = []; |
|
| 136 | + } |
|
| 137 | + if (!array_key_exists('personal', $array['settings'])) { |
|
| 138 | + $array['settings']['personal'] = []; |
|
| 139 | + } |
|
| 140 | + if (!array_key_exists('personal-section', $array['settings'])) { |
|
| 141 | + $array['settings']['personal-section'] = []; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if (array_key_exists('types', $array)) { |
|
| 145 | - if (is_array($array['types'])) { |
|
| 146 | - foreach ($array['types'] as $type => $v) { |
|
| 147 | - unset($array['types'][$type]); |
|
| 148 | - if (is_string($type)) { |
|
| 149 | - $array['types'][] = $type; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } else { |
|
| 153 | - $array['types'] = []; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 157 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 158 | - } |
|
| 159 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 160 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 161 | - } |
|
| 162 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 163 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 164 | - } |
|
| 165 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 166 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 167 | - } |
|
| 168 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 169 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 170 | - } |
|
| 171 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 172 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 173 | - } |
|
| 174 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 175 | - $array['commands'] = $array['commands']['command']; |
|
| 176 | - } |
|
| 177 | - if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 178 | - $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 179 | - } |
|
| 180 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 181 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 182 | - } |
|
| 183 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 184 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 185 | - } |
|
| 186 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 187 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 188 | - } |
|
| 189 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 190 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 191 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 192 | - ) { |
|
| 193 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 194 | - } |
|
| 195 | - if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 196 | - $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 197 | - } |
|
| 198 | - if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 199 | - $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 200 | - } |
|
| 201 | - if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 202 | - $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 203 | - } |
|
| 204 | - if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 205 | - $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 206 | - } |
|
| 144 | + if (array_key_exists('types', $array)) { |
|
| 145 | + if (is_array($array['types'])) { |
|
| 146 | + foreach ($array['types'] as $type => $v) { |
|
| 147 | + unset($array['types'][$type]); |
|
| 148 | + if (is_string($type)) { |
|
| 149 | + $array['types'][] = $type; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } else { |
|
| 153 | + $array['types'] = []; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 157 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
| 158 | + } |
|
| 159 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 160 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
| 161 | + } |
|
| 162 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 163 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
| 164 | + } |
|
| 165 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 166 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
| 167 | + } |
|
| 168 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 169 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
| 170 | + } |
|
| 171 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 172 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
| 173 | + } |
|
| 174 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 175 | + $array['commands'] = $array['commands']['command']; |
|
| 176 | + } |
|
| 177 | + if (isset($array['two-factor-providers']['provider']) && is_array($array['two-factor-providers']['provider'])) { |
|
| 178 | + $array['two-factor-providers'] = $array['two-factor-providers']['provider']; |
|
| 179 | + } |
|
| 180 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
| 181 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
| 182 | + } |
|
| 183 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
| 184 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
| 185 | + } |
|
| 186 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
| 187 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
| 188 | + } |
|
| 189 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 190 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
| 191 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
| 192 | + ) { |
|
| 193 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
| 194 | + } |
|
| 195 | + if (isset($array['settings']['admin']) && !is_array($array['settings']['admin'])) { |
|
| 196 | + $array['settings']['admin'] = [$array['settings']['admin']]; |
|
| 197 | + } |
|
| 198 | + if (isset($array['settings']['admin-section']) && !is_array($array['settings']['admin-section'])) { |
|
| 199 | + $array['settings']['admin-section'] = [$array['settings']['admin-section']]; |
|
| 200 | + } |
|
| 201 | + if (isset($array['settings']['personal']) && !is_array($array['settings']['personal'])) { |
|
| 202 | + $array['settings']['personal'] = [$array['settings']['personal']]; |
|
| 203 | + } |
|
| 204 | + if (isset($array['settings']['personal-section']) && !is_array($array['settings']['personal-section'])) { |
|
| 205 | + $array['settings']['personal-section'] = [$array['settings']['personal-section']]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 209 | - $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 210 | - } |
|
| 208 | + if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { |
|
| 209 | + $array['navigations']['navigation'] = [$array['navigations']['navigation']]; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - if ($this->cache !== null) { |
|
| 213 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 214 | - } |
|
| 215 | - return $array; |
|
| 216 | - } |
|
| 212 | + if ($this->cache !== null) { |
|
| 213 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
| 214 | + } |
|
| 215 | + return $array; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @param $data |
|
| 220 | - * @return bool |
|
| 221 | - */ |
|
| 222 | - private function isNavigationItem($data): bool { |
|
| 223 | - return isset($data['name'], $data['route']); |
|
| 224 | - } |
|
| 218 | + /** |
|
| 219 | + * @param $data |
|
| 220 | + * @return bool |
|
| 221 | + */ |
|
| 222 | + private function isNavigationItem($data): bool { |
|
| 223 | + return isset($data['name'], $data['route']); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * @param \SimpleXMLElement $xml |
|
| 228 | - * @return array |
|
| 229 | - */ |
|
| 230 | - public function xmlToArray($xml) { |
|
| 231 | - if (!$xml->children()) { |
|
| 232 | - return (string)$xml; |
|
| 233 | - } |
|
| 226 | + /** |
|
| 227 | + * @param \SimpleXMLElement $xml |
|
| 228 | + * @return array |
|
| 229 | + */ |
|
| 230 | + public function xmlToArray($xml) { |
|
| 231 | + if (!$xml->children()) { |
|
| 232 | + return (string)$xml; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - $array = []; |
|
| 236 | - foreach ($xml->children() as $element => $node) { |
|
| 237 | - $totalElement = count($xml->{$element}); |
|
| 235 | + $array = []; |
|
| 236 | + foreach ($xml->children() as $element => $node) { |
|
| 237 | + $totalElement = count($xml->{$element}); |
|
| 238 | 238 | |
| 239 | - if (!isset($array[$element])) { |
|
| 240 | - $array[$element] = $totalElement > 1 ? [] : ""; |
|
| 241 | - } |
|
| 242 | - /** @var \SimpleXMLElement $node */ |
|
| 243 | - // Has attributes |
|
| 244 | - if ($attributes = $node->attributes()) { |
|
| 245 | - $data = [ |
|
| 246 | - '@attributes' => [], |
|
| 247 | - ]; |
|
| 248 | - if (!count($node->children())){ |
|
| 249 | - $value = (string)$node; |
|
| 250 | - if (!empty($value)) { |
|
| 251 | - $data['@value'] = (string)$node; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
| 255 | - } |
|
| 256 | - foreach ($attributes as $attr => $value) { |
|
| 257 | - $data['@attributes'][$attr] = (string)$value; |
|
| 258 | - } |
|
| 239 | + if (!isset($array[$element])) { |
|
| 240 | + $array[$element] = $totalElement > 1 ? [] : ""; |
|
| 241 | + } |
|
| 242 | + /** @var \SimpleXMLElement $node */ |
|
| 243 | + // Has attributes |
|
| 244 | + if ($attributes = $node->attributes()) { |
|
| 245 | + $data = [ |
|
| 246 | + '@attributes' => [], |
|
| 247 | + ]; |
|
| 248 | + if (!count($node->children())){ |
|
| 249 | + $value = (string)$node; |
|
| 250 | + if (!empty($value)) { |
|
| 251 | + $data['@value'] = (string)$node; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
| 255 | + } |
|
| 256 | + foreach ($attributes as $attr => $value) { |
|
| 257 | + $data['@attributes'][$attr] = (string)$value; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - if ($totalElement > 1) { |
|
| 261 | - $array[$element][] = $data; |
|
| 262 | - } else { |
|
| 263 | - $array[$element] = $data; |
|
| 264 | - } |
|
| 265 | - // Just a value |
|
| 266 | - } else { |
|
| 267 | - if ($totalElement > 1) { |
|
| 268 | - $array[$element][] = $this->xmlToArray($node); |
|
| 269 | - } else { |
|
| 270 | - $array[$element] = $this->xmlToArray($node); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 260 | + if ($totalElement > 1) { |
|
| 261 | + $array[$element][] = $data; |
|
| 262 | + } else { |
|
| 263 | + $array[$element] = $data; |
|
| 264 | + } |
|
| 265 | + // Just a value |
|
| 266 | + } else { |
|
| 267 | + if ($totalElement > 1) { |
|
| 268 | + $array[$element][] = $this->xmlToArray($node); |
|
| 269 | + } else { |
|
| 270 | + $array[$element] = $this->xmlToArray($node); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - return $array; |
|
| 276 | - } |
|
| 275 | + return $array; |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | if ($this->cache !== null) { |
| 56 | - $fileCacheKey = $file . filemtime($file); |
|
| 56 | + $fileCacheKey = $file.filemtime($file); |
|
| 57 | 57 | if ($cachedValue = $this->cache->get($fileCacheKey)) { |
| 58 | 58 | return json_decode($cachedValue, true); |
| 59 | 59 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function xmlToArray($xml) { |
| 231 | 231 | if (!$xml->children()) { |
| 232 | - return (string)$xml; |
|
| 232 | + return (string) $xml; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $array = []; |
@@ -245,16 +245,16 @@ discard block |
||
| 245 | 245 | $data = [ |
| 246 | 246 | '@attributes' => [], |
| 247 | 247 | ]; |
| 248 | - if (!count($node->children())){ |
|
| 249 | - $value = (string)$node; |
|
| 248 | + if (!count($node->children())) { |
|
| 249 | + $value = (string) $node; |
|
| 250 | 250 | if (!empty($value)) { |
| 251 | - $data['@value'] = (string)$node; |
|
| 251 | + $data['@value'] = (string) $node; |
|
| 252 | 252 | } |
| 253 | 253 | } else { |
| 254 | 254 | $data = array_merge($data, $this->xmlToArray($node)); |
| 255 | 255 | } |
| 256 | 256 | foreach ($attributes as $attr => $value) { |
| 257 | - $data['@attributes'][$attr] = (string)$value; |
|
| 257 | + $data['@attributes'][$attr] = (string) $value; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | if ($totalElement > 1) { |
@@ -44,290 +44,290 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | |
| 46 | 46 | class NavigationManager implements INavigationManager { |
| 47 | - protected $entries = []; |
|
| 48 | - protected $closureEntries = []; |
|
| 49 | - protected $activeEntry; |
|
| 50 | - /** @var bool */ |
|
| 51 | - protected $init = false; |
|
| 52 | - /** @var IAppManager|AppManager */ |
|
| 53 | - protected $appManager; |
|
| 54 | - /** @var IURLGenerator */ |
|
| 55 | - private $urlGenerator; |
|
| 56 | - /** @var IFactory */ |
|
| 57 | - private $l10nFac; |
|
| 58 | - /** @var IUserSession */ |
|
| 59 | - private $userSession; |
|
| 60 | - /** @var IGroupManager|Manager */ |
|
| 61 | - private $groupManager; |
|
| 62 | - /** @var IConfig */ |
|
| 63 | - private $config; |
|
| 47 | + protected $entries = []; |
|
| 48 | + protected $closureEntries = []; |
|
| 49 | + protected $activeEntry; |
|
| 50 | + /** @var bool */ |
|
| 51 | + protected $init = false; |
|
| 52 | + /** @var IAppManager|AppManager */ |
|
| 53 | + protected $appManager; |
|
| 54 | + /** @var IURLGenerator */ |
|
| 55 | + private $urlGenerator; |
|
| 56 | + /** @var IFactory */ |
|
| 57 | + private $l10nFac; |
|
| 58 | + /** @var IUserSession */ |
|
| 59 | + private $userSession; |
|
| 60 | + /** @var IGroupManager|Manager */ |
|
| 61 | + private $groupManager; |
|
| 62 | + /** @var IConfig */ |
|
| 63 | + private $config; |
|
| 64 | 64 | |
| 65 | - public function __construct(IAppManager $appManager, |
|
| 66 | - IURLGenerator $urlGenerator, |
|
| 67 | - IFactory $l10nFac, |
|
| 68 | - IUserSession $userSession, |
|
| 69 | - IGroupManager $groupManager, |
|
| 70 | - IConfig $config) { |
|
| 71 | - $this->appManager = $appManager; |
|
| 72 | - $this->urlGenerator = $urlGenerator; |
|
| 73 | - $this->l10nFac = $l10nFac; |
|
| 74 | - $this->userSession = $userSession; |
|
| 75 | - $this->groupManager = $groupManager; |
|
| 76 | - $this->config = $config; |
|
| 77 | - } |
|
| 65 | + public function __construct(IAppManager $appManager, |
|
| 66 | + IURLGenerator $urlGenerator, |
|
| 67 | + IFactory $l10nFac, |
|
| 68 | + IUserSession $userSession, |
|
| 69 | + IGroupManager $groupManager, |
|
| 70 | + IConfig $config) { |
|
| 71 | + $this->appManager = $appManager; |
|
| 72 | + $this->urlGenerator = $urlGenerator; |
|
| 73 | + $this->l10nFac = $l10nFac; |
|
| 74 | + $this->userSession = $userSession; |
|
| 75 | + $this->groupManager = $groupManager; |
|
| 76 | + $this->config = $config; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Creates a new navigation entry |
|
| 81 | - * |
|
| 82 | - * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
| 83 | - * The use of a closure is preferred, because it will avoid |
|
| 84 | - * loading the routing of your app, unless required. |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - public function add($entry) { |
|
| 88 | - if ($entry instanceof \Closure) { |
|
| 89 | - $this->closureEntries[] = $entry; |
|
| 90 | - return; |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * Creates a new navigation entry |
|
| 81 | + * |
|
| 82 | + * @param array|\Closure $entry Array containing: id, name, order, icon and href key |
|
| 83 | + * The use of a closure is preferred, because it will avoid |
|
| 84 | + * loading the routing of your app, unless required. |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + public function add($entry) { |
|
| 88 | + if ($entry instanceof \Closure) { |
|
| 89 | + $this->closureEntries[] = $entry; |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $entry['active'] = false; |
|
| 94 | - if(!isset($entry['icon'])) { |
|
| 95 | - $entry['icon'] = ''; |
|
| 96 | - } |
|
| 97 | - if(!isset($entry['classes'])) { |
|
| 98 | - $entry['classes'] = ''; |
|
| 99 | - } |
|
| 100 | - if(!isset($entry['type'])) { |
|
| 101 | - $entry['type'] = 'link'; |
|
| 102 | - } |
|
| 103 | - $this->entries[$entry['id']] = $entry; |
|
| 104 | - } |
|
| 93 | + $entry['active'] = false; |
|
| 94 | + if(!isset($entry['icon'])) { |
|
| 95 | + $entry['icon'] = ''; |
|
| 96 | + } |
|
| 97 | + if(!isset($entry['classes'])) { |
|
| 98 | + $entry['classes'] = ''; |
|
| 99 | + } |
|
| 100 | + if(!isset($entry['type'])) { |
|
| 101 | + $entry['type'] = 'link'; |
|
| 102 | + } |
|
| 103 | + $this->entries[$entry['id']] = $entry; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Get a list of navigation entries |
|
| 108 | - * |
|
| 109 | - * @param string $type type of the navigation entries |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function getAll(string $type = 'link'): array { |
|
| 113 | - $this->init(); |
|
| 114 | - foreach ($this->closureEntries as $c) { |
|
| 115 | - $this->add($c()); |
|
| 116 | - } |
|
| 117 | - $this->closureEntries = array(); |
|
| 106 | + /** |
|
| 107 | + * Get a list of navigation entries |
|
| 108 | + * |
|
| 109 | + * @param string $type type of the navigation entries |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function getAll(string $type = 'link'): array { |
|
| 113 | + $this->init(); |
|
| 114 | + foreach ($this->closureEntries as $c) { |
|
| 115 | + $this->add($c()); |
|
| 116 | + } |
|
| 117 | + $this->closureEntries = array(); |
|
| 118 | 118 | |
| 119 | - $result = $this->entries; |
|
| 120 | - if ($type !== 'all') { |
|
| 121 | - $result = array_filter($this->entries, function($entry) use ($type) { |
|
| 122 | - return $entry['type'] === $type; |
|
| 123 | - }); |
|
| 124 | - } |
|
| 119 | + $result = $this->entries; |
|
| 120 | + if ($type !== 'all') { |
|
| 121 | + $result = array_filter($this->entries, function($entry) use ($type) { |
|
| 122 | + return $entry['type'] === $type; |
|
| 123 | + }); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - return $this->proceedNavigation($result); |
|
| 127 | - } |
|
| 126 | + return $this->proceedNavigation($result); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Sort navigation entries by order, name and set active flag |
|
| 131 | - * |
|
| 132 | - * @param array $list |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - private function proceedNavigation(array $list): array { |
|
| 136 | - uasort($list, function($a, $b) { |
|
| 137 | - if (isset($a['order']) && isset($b['order'])) { |
|
| 138 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 139 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
| 140 | - return isset($a['order']) ? -1 : 1; |
|
| 141 | - } else { |
|
| 142 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 143 | - } |
|
| 144 | - }); |
|
| 129 | + /** |
|
| 130 | + * Sort navigation entries by order, name and set active flag |
|
| 131 | + * |
|
| 132 | + * @param array $list |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + private function proceedNavigation(array $list): array { |
|
| 136 | + uasort($list, function($a, $b) { |
|
| 137 | + if (isset($a['order']) && isset($b['order'])) { |
|
| 138 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 139 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
| 140 | + return isset($a['order']) ? -1 : 1; |
|
| 141 | + } else { |
|
| 142 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
| 143 | + } |
|
| 144 | + }); |
|
| 145 | 145 | |
| 146 | - $activeApp = $this->getActiveEntry(); |
|
| 147 | - if ($activeApp !== null) { |
|
| 148 | - foreach ($list as $index => &$navEntry) { |
|
| 149 | - if ($navEntry['id'] == $activeApp) { |
|
| 150 | - $navEntry['active'] = true; |
|
| 151 | - } else { |
|
| 152 | - $navEntry['active'] = false; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - unset($navEntry); |
|
| 156 | - } |
|
| 146 | + $activeApp = $this->getActiveEntry(); |
|
| 147 | + if ($activeApp !== null) { |
|
| 148 | + foreach ($list as $index => &$navEntry) { |
|
| 149 | + if ($navEntry['id'] == $activeApp) { |
|
| 150 | + $navEntry['active'] = true; |
|
| 151 | + } else { |
|
| 152 | + $navEntry['active'] = false; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + unset($navEntry); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - return $list; |
|
| 159 | - } |
|
| 158 | + return $list; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * removes all the entries |
|
| 164 | - */ |
|
| 165 | - public function clear($loadDefaultLinks = true) { |
|
| 166 | - $this->entries = []; |
|
| 167 | - $this->closureEntries = []; |
|
| 168 | - $this->init = !$loadDefaultLinks; |
|
| 169 | - } |
|
| 162 | + /** |
|
| 163 | + * removes all the entries |
|
| 164 | + */ |
|
| 165 | + public function clear($loadDefaultLinks = true) { |
|
| 166 | + $this->entries = []; |
|
| 167 | + $this->closureEntries = []; |
|
| 168 | + $this->init = !$loadDefaultLinks; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Sets the current navigation entry of the currently running app |
|
| 173 | - * @param string $id of the app entry to activate (from added $entry) |
|
| 174 | - */ |
|
| 175 | - public function setActiveEntry($id) { |
|
| 176 | - $this->activeEntry = $id; |
|
| 177 | - } |
|
| 171 | + /** |
|
| 172 | + * Sets the current navigation entry of the currently running app |
|
| 173 | + * @param string $id of the app entry to activate (from added $entry) |
|
| 174 | + */ |
|
| 175 | + public function setActiveEntry($id) { |
|
| 176 | + $this->activeEntry = $id; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * gets the active Menu entry |
|
| 181 | - * @return string id or empty string |
|
| 182 | - * |
|
| 183 | - * This function returns the id of the active navigation entry (set by |
|
| 184 | - * setActiveEntry |
|
| 185 | - */ |
|
| 186 | - public function getActiveEntry() { |
|
| 187 | - return $this->activeEntry; |
|
| 188 | - } |
|
| 179 | + /** |
|
| 180 | + * gets the active Menu entry |
|
| 181 | + * @return string id or empty string |
|
| 182 | + * |
|
| 183 | + * This function returns the id of the active navigation entry (set by |
|
| 184 | + * setActiveEntry |
|
| 185 | + */ |
|
| 186 | + public function getActiveEntry() { |
|
| 187 | + return $this->activeEntry; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - private function init() { |
|
| 191 | - if ($this->init) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $this->init = true; |
|
| 190 | + private function init() { |
|
| 191 | + if ($this->init) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $this->init = true; |
|
| 195 | 195 | |
| 196 | - $l = $this->l10nFac->get('lib'); |
|
| 197 | - if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
| 198 | - $this->add([ |
|
| 199 | - 'type' => 'settings', |
|
| 200 | - 'id' => 'help', |
|
| 201 | - 'order' => 5, |
|
| 202 | - 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
| 203 | - 'name' => $l->t('Help'), |
|
| 204 | - 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
| 205 | - ]); |
|
| 206 | - } |
|
| 196 | + $l = $this->l10nFac->get('lib'); |
|
| 197 | + if ($this->config->getSystemValue('knowledgebaseenabled', true)) { |
|
| 198 | + $this->add([ |
|
| 199 | + 'type' => 'settings', |
|
| 200 | + 'id' => 'help', |
|
| 201 | + 'order' => 5, |
|
| 202 | + 'href' => $this->urlGenerator->linkToRoute('settings_help'), |
|
| 203 | + 'name' => $l->t('Help'), |
|
| 204 | + 'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'), |
|
| 205 | + ]); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - if ($this->userSession->isLoggedIn()) { |
|
| 209 | - if ($this->isAdmin()) { |
|
| 210 | - // App management |
|
| 211 | - $this->add([ |
|
| 212 | - 'type' => 'settings', |
|
| 213 | - 'id' => 'core_apps', |
|
| 214 | - 'order' => 3, |
|
| 215 | - 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 216 | - 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 217 | - 'name' => $l->t('Apps'), |
|
| 218 | - ]); |
|
| 219 | - } |
|
| 208 | + if ($this->userSession->isLoggedIn()) { |
|
| 209 | + if ($this->isAdmin()) { |
|
| 210 | + // App management |
|
| 211 | + $this->add([ |
|
| 212 | + 'type' => 'settings', |
|
| 213 | + 'id' => 'core_apps', |
|
| 214 | + 'order' => 3, |
|
| 215 | + 'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'), |
|
| 216 | + 'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'), |
|
| 217 | + 'name' => $l->t('Apps'), |
|
| 218 | + ]); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - // Personal and (if applicable) admin settings |
|
| 222 | - $this->add([ |
|
| 223 | - 'type' => 'settings', |
|
| 224 | - 'id' => 'settings', |
|
| 225 | - 'order' => 1, |
|
| 226 | - 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 227 | - 'name' => $l->t('Settings'), |
|
| 228 | - 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 229 | - ]); |
|
| 221 | + // Personal and (if applicable) admin settings |
|
| 222 | + $this->add([ |
|
| 223 | + 'type' => 'settings', |
|
| 224 | + 'id' => 'settings', |
|
| 225 | + 'order' => 1, |
|
| 226 | + 'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
|
| 227 | + 'name' => $l->t('Settings'), |
|
| 228 | + 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), |
|
| 229 | + ]); |
|
| 230 | 230 | |
| 231 | - $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
| 232 | - if($logoutUrl !== '') { |
|
| 233 | - // Logout |
|
| 234 | - $this->add([ |
|
| 235 | - 'type' => 'settings', |
|
| 236 | - 'id' => 'logout', |
|
| 237 | - 'order' => 99999, |
|
| 238 | - 'href' => $logoutUrl, |
|
| 239 | - 'name' => $l->t('Log out'), |
|
| 240 | - 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 241 | - ]); |
|
| 242 | - } |
|
| 231 | + $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
|
| 232 | + if($logoutUrl !== '') { |
|
| 233 | + // Logout |
|
| 234 | + $this->add([ |
|
| 235 | + 'type' => 'settings', |
|
| 236 | + 'id' => 'logout', |
|
| 237 | + 'order' => 99999, |
|
| 238 | + 'href' => $logoutUrl, |
|
| 239 | + 'name' => $l->t('Log out'), |
|
| 240 | + 'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'), |
|
| 241 | + ]); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - if ($this->isSubadmin()) { |
|
| 245 | - // User management |
|
| 246 | - $this->add([ |
|
| 247 | - 'type' => 'settings', |
|
| 248 | - 'id' => 'core_users', |
|
| 249 | - 'order' => 4, |
|
| 250 | - 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
| 251 | - 'name' => $l->t('Users'), |
|
| 252 | - 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 253 | - ]); |
|
| 254 | - } |
|
| 255 | - } |
|
| 244 | + if ($this->isSubadmin()) { |
|
| 245 | + // User management |
|
| 246 | + $this->add([ |
|
| 247 | + 'type' => 'settings', |
|
| 248 | + 'id' => 'core_users', |
|
| 249 | + 'order' => 4, |
|
| 250 | + 'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'), |
|
| 251 | + 'name' => $l->t('Users'), |
|
| 252 | + 'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'), |
|
| 253 | + ]); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ($this->appManager === 'null') { |
|
| 258 | - return; |
|
| 259 | - } |
|
| 257 | + if ($this->appManager === 'null') { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - if ($this->userSession->isLoggedIn()) { |
|
| 262 | - $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
| 263 | - } else { |
|
| 264 | - $apps = $this->appManager->getInstalledApps(); |
|
| 265 | - } |
|
| 261 | + if ($this->userSession->isLoggedIn()) { |
|
| 262 | + $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser()); |
|
| 263 | + } else { |
|
| 264 | + $apps = $this->appManager->getInstalledApps(); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - foreach ($apps as $app) { |
|
| 268 | - if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
| 269 | - continue; |
|
| 270 | - } |
|
| 267 | + foreach ($apps as $app) { |
|
| 268 | + if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) { |
|
| 269 | + continue; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // load plugins and collections from info.xml |
|
| 273 | - $info = $this->appManager->getAppInfo($app); |
|
| 274 | - if (!isset($info['navigations']['navigation'])) { |
|
| 275 | - continue; |
|
| 276 | - } |
|
| 277 | - foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
| 278 | - if (!isset($nav['name'])) { |
|
| 279 | - continue; |
|
| 280 | - } |
|
| 281 | - if (!isset($nav['route'])) { |
|
| 282 | - continue; |
|
| 283 | - } |
|
| 284 | - $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 285 | - if ($role === 'admin' && !$this->isAdmin()) { |
|
| 286 | - continue; |
|
| 287 | - } |
|
| 288 | - $l = $this->l10nFac->get($app); |
|
| 289 | - $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 290 | - $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 291 | - $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
| 292 | - $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
| 293 | - $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 294 | - foreach ([$icon, "$app.svg"] as $i) { |
|
| 295 | - try { |
|
| 296 | - $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 297 | - break; |
|
| 298 | - } catch (\RuntimeException $ex) { |
|
| 299 | - // no icon? - ignore it then |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - if ($icon === null) { |
|
| 303 | - $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 304 | - } |
|
| 272 | + // load plugins and collections from info.xml |
|
| 273 | + $info = $this->appManager->getAppInfo($app); |
|
| 274 | + if (!isset($info['navigations']['navigation'])) { |
|
| 275 | + continue; |
|
| 276 | + } |
|
| 277 | + foreach ($info['navigations']['navigation'] as $key => $nav) { |
|
| 278 | + if (!isset($nav['name'])) { |
|
| 279 | + continue; |
|
| 280 | + } |
|
| 281 | + if (!isset($nav['route'])) { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 284 | + $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all'; |
|
| 285 | + if ($role === 'admin' && !$this->isAdmin()) { |
|
| 286 | + continue; |
|
| 287 | + } |
|
| 288 | + $l = $this->l10nFac->get($app); |
|
| 289 | + $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 290 | + $order = isset($nav['order']) ? $nav['order'] : 100; |
|
| 291 | + $type = isset($nav['type']) ? $nav['type'] : 'link'; |
|
| 292 | + $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |
|
| 293 | + $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg'; |
|
| 294 | + foreach ([$icon, "$app.svg"] as $i) { |
|
| 295 | + try { |
|
| 296 | + $icon = $this->urlGenerator->imagePath($app, $i); |
|
| 297 | + break; |
|
| 298 | + } catch (\RuntimeException $ex) { |
|
| 299 | + // no icon? - ignore it then |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + if ($icon === null) { |
|
| 303 | + $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - $this->add([ |
|
| 307 | - 'id' => $id, |
|
| 308 | - 'order' => $order, |
|
| 309 | - 'href' => $route, |
|
| 310 | - 'icon' => $icon, |
|
| 311 | - 'type' => $type, |
|
| 312 | - 'name' => $l->t($nav['name']), |
|
| 313 | - ]); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 306 | + $this->add([ |
|
| 307 | + 'id' => $id, |
|
| 308 | + 'order' => $order, |
|
| 309 | + 'href' => $route, |
|
| 310 | + 'icon' => $icon, |
|
| 311 | + 'type' => $type, |
|
| 312 | + 'name' => $l->t($nav['name']), |
|
| 313 | + ]); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - private function isAdmin() { |
|
| 319 | - $user = $this->userSession->getUser(); |
|
| 320 | - if ($user !== null) { |
|
| 321 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 322 | - } |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 318 | + private function isAdmin() { |
|
| 319 | + $user = $this->userSession->getUser(); |
|
| 320 | + if ($user !== null) { |
|
| 321 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 322 | + } |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - private function isSubadmin() { |
|
| 327 | - $user = $this->userSession->getUser(); |
|
| 328 | - if ($user !== null) { |
|
| 329 | - return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 330 | - } |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 326 | + private function isSubadmin() { |
|
| 327 | + $user = $this->userSession->getUser(); |
|
| 328 | + if ($user !== null) { |
|
| 329 | + return $this->groupManager->getSubAdmin()->isSubAdmin($user); |
|
| 330 | + } |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | 333 | } |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $entry['active'] = false; |
| 94 | - if(!isset($entry['icon'])) { |
|
| 94 | + if (!isset($entry['icon'])) { |
|
| 95 | 95 | $entry['icon'] = ''; |
| 96 | 96 | } |
| 97 | - if(!isset($entry['classes'])) { |
|
| 97 | + if (!isset($entry['classes'])) { |
|
| 98 | 98 | $entry['classes'] = ''; |
| 99 | 99 | } |
| 100 | - if(!isset($entry['type'])) { |
|
| 100 | + if (!isset($entry['type'])) { |
|
| 101 | 101 | $entry['type'] = 'link'; |
| 102 | 102 | } |
| 103 | 103 | $this->entries[$entry['id']] = $entry; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | ]); |
| 230 | 230 | |
| 231 | 231 | $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator); |
| 232 | - if($logoutUrl !== '') { |
|
| 232 | + if ($logoutUrl !== '') { |
|
| 233 | 233 | // Logout |
| 234 | 234 | $this->add([ |
| 235 | 235 | 'type' => 'settings', |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | continue; |
| 287 | 287 | } |
| 288 | 288 | $l = $this->l10nFac->get($app); |
| 289 | - $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); |
|
| 289 | + $id = $nav['id'] ?? $app.($key === 0 ? '' : $key); |
|
| 290 | 290 | $order = isset($nav['order']) ? $nav['order'] : 100; |
| 291 | 291 | $type = isset($nav['type']) ? $nav['type'] : 'link'; |
| 292 | 292 | $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; |