52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /* Copyright (C) 2021  Alexander Rosenberg
 | |
|  * This file is AGPL v3. See LICENSE file for more information
 | |
|  */
 | |
| const CONFIG_PATH = AM_OPTIONS['root'] . '/config.json';
 | |
| 
 | |
| function display_error_message($msg, $html_tags = '') {
 | |
|     echo '<div ' . $html_tags . ' class=".error-message">' . htmlspecialchars($msg, ENT_QUOTES | ENT_HTML5) . '</div>';
 | |
| }
 | |
| 
 | |
| $LIBRARY_INFO = [];
 | |
| 
 | |
| function read_global_config() {
 | |
|     if (!file_exists(CONFIG_PATH)) {
 | |
|         display_error_message('Could not find config file!');
 | |
|         exit(0);
 | |
|     }
 | |
|     $config_text = file_get_contents(CONFIG_PATH);
 | |
|     if ($config_text == null) {
 | |
|         display_error_message('Could not read config file!');
 | |
|         exit(0);
 | |
|     }
 | |
|     $config_json = json_decode($config_text);
 | |
|     if ($config_json == null) {
 | |
|         display_error_message(json_last_error_msg() . '! Could not decode config file!');
 | |
|         exit(0);
 | |
|     }
 | |
|     $library_name = $config_json->{'library_name'};
 | |
|     if ($library_name == null) {
 | |
|         $library_name = "An Unknown Person's Library";
 | |
|     }
 | |
|     $library_albums = $config_json->{'albums'};
 | |
|     if ($library_albums == null) {
 | |
|         $library_albums = [];
 | |
|     }
 | |
|     $photos_license = $config_json->{'license'};
 | |
|     if ($photos_license == null) {
 | |
|         $photos_license = "Photos may be copyrighted content";
 | |
|     } else {
 | |
|         $photos_license = "Photos are " . $photos_license;
 | |
|     }
 | |
|     global $LIBRARY_INFO;
 | |
|     $LIBRARY_INFO = [
 | |
|         'name' => $library_name,
 | |
|         'albums' => $library_albums,
 | |
|         'license' => $photos_license
 | |
|     ];
 | |
| }
 | |
| 
 | |
| read_global_config();
 | |
| ?>
 |