diff --git a/Web/Themes/Themepacks.php b/Web/Themes/Themepacks.php index 3010f6e1..1c8e5ca3 100644 --- a/Web/Themes/Themepacks.php +++ b/Web/Themes/Themepacks.php @@ -1,94 +1,89 @@ -getId(); - if(isset($this->loadedThemepacks[$tid])) + $tid = $theme->getId(); + if (isset($this->loadedThemepacks[$tid])) trigger_error("Duplicate theme $tid found at $themeDir, skipping...", E_USER_WARNING); else $this->loadedThemepacks[$tid] = $theme; - } catch(\Exception $e) { + } catch (\Exception $e) { trigger_error("Could not load theme at $themeDir, skipping...", E_USER_WARNING); } } } - - private function installUnpacked(string $path): bool - { + + private function installUnpacked(string $path): bool { try { $theme = Themepack::themepackFromDir($path); - $tid = $theme->getId(); - if(isset($this->loadedThemepacks[$tid])) + $tid = $theme->getId(); + if (isset($this->loadedThemepacks[$tid])) return false; - + rename($path, OPENVK_ROOT . "/themepacks/$tid"); $this->loadedThemepacks[$tid] = $theme; return true; - } catch(\Exception $e) { + } catch (\Exception $e) { return false; } } - - function getThemeList(): \Traversable - { - foreach($this->loadedThemepacks as $id => $theme) - if($theme->isEnabled()) + + function getThemeList(): \Traversable { + foreach ($this->loadedThemepacks as $id => $theme) + if ($theme->isEnabled()) yield $id => ($theme->getName(Session::i()->get("lang", "ru"))); } - - function getAllThemes(): array - { + + function getAllThemes(): array { return $this->loadedThemepacks; } - + /* ArrayAccess */ - - function offsetExists($offset): bool - { + + function offsetExists($offset): bool { return $offset === Themepacks::DEFAULT_THEME_ID ? false : isset($this->loadedThemepacks[$offset]); } - - function offsetGet($offset) - { + + function offsetGet($offset) { return $this->loadedThemepacks[$offset]; } - - function offsetSet($offset, $value): void - { + + function offsetSet($offset, $value): void { throw new ISE("Theme substitution in runtime is prohbited"); } - - function offsetUnset($offset): void - { + + function offsetUnset($offset): void { $this->uninstall($offset); } - + /* /ArrayAccess */ - - function install(string $archivePath): bool - { - if(!file_exists($archivePath)) + + function install(string $archivePath): bool { + if (!file_exists($archivePath)) return false; - + $tmpDir = mkdir(tempnam(OPENVK_ROOT . "/tmp/themepack_artifacts/", "themex_")); try { $archive = new \CabArchive($archivePath); $archive->extract($tmpDir); - + return $this->installUnpacked($tmpDir); } catch (\Exception $e) { return false; @@ -96,16 +91,15 @@ class Themepacks implements \ArrayAccess rmdir($tmpDir); } } - - function uninstall(string $id): bool - { - if(!isset($loadedThemepacks[$id])) + + function uninstall(string $id): bool { + if (!isset($loadedThemepacks[$id])) return false; - + rmdir(OPENVK_ROOT . "/themepacks/$id"); unset($loadedThemepacks[$id]); return true; } - + use TSimpleSingleton; -} +} // Я рыгнул \ No newline at end of file