$colorScheme, 'view' => $view, 'title' => $title, 'visibility' => $visibility, 'desc' => $desc ]; $config = Yaml::dump($userConfig); file_put_contents('../data/config.yaml', $config); $this->clearCache(); } /** * Save services list * * @return void */ function saveServices(): array { try { $value = Yaml::parse(trim($_POST['services'], 2)); } catch (ParseException $exception) { return ['status' => 'error', 'message' => $exception->getMessage(), 'content' => $_POST['services']]; } file_put_contents('../data/services.yaml', $_POST['services']); $this->clearCache(); return ['status' => 'success', 'message' => '']; } /** * Get the configuration settings. * * @param array $defConfig The default configuration settings. * * @return array The configuration settings. */ public function getConfig(array $defConfig): array { if (file_exists('../data/config.yaml')) { $userConfig = Yaml::parseFile('../data/config.yaml'); if (empty($userConfig)) { return $defConfig; } $config = array_merge($defConfig, $userConfig); $this->config = $config; return $config; } $this->config = $defConfig; return $defConfig; } /** * Clear the cache file. * * @return void */ public function clearCache(): void { if (file_exists('../cache/index.html')) { unlink('../cache/index.html'); } } /** * Initialize the data directories. * * @return void */ static function initializeDataDir(): void { if (!is_dir(('../data/assets/css'))) { mkdir('../data/assets/css', 0775, true); } if (!is_dir(('../data/assets/icons'))) { mkdir('../data/assets/icons', 0775, true); } if (!is_dir(('../data/assets/js'))) { mkdir('../data/assets/js', 0775, true); } if (!is_dir(('../data/imgs/favicons'))) { mkdir('../data/imgs/favicons', 0775, true); } if (!is_dir(('../data/imgs/screenshots'))) { mkdir('../data/imgs/screenshots', 0775, true); } } public function getServices() { if (file_exists('../data/services.yaml')) { $services = Yaml::parseFile('../data/services.yaml'); } else { $services = [ 0 => [ 'title' => 'Wikipedia', 'screenshot' => 'wikipedia.png', 'favicon' => 'wikipedia.png', 'link' => 'https://en.wikipedia.org/wiki/Dashboard_(computing)', 'appHome' => 'https://www.mediawiki.org/wiki/MediaWiki', 'location' => 'web', 'desc' => 'Wikipedia, the free encyclopedia', 'type' => 'webapp' ], [ 'title' => 'Awesome-Selfhosted', 'screenshot' => 'Awesome-Selfhosted.png', 'favicon' => 'Awesome-Selfhosted.ico', 'link' => 'https://awesome-selfhosted.net/', 'appHome' => 'https://www.mediawiki.org/wiki/MediaWiki', 'location' => 'web', 'desc' => 'A list of Free Software network services and web applications which can be hosted on your own servers', 'type' => 'webapp' ] ]; } return $services; } }