You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
| <?php
 | |
|     /**
 | |
|      * Return local path to room invite code.
 | |
| 	 * @param string $room_id Id of room to locate QR code for.
 | |
| 	 */
 | |
| 	function room_qr_code_path(string $room_id): string {
 | |
| 		global $QR_CODES;
 | |
| 		return "$QR_CODES/$room_id.png";
 | |
| 	}
 | |
| 
 | |
|     /**
 | |
|      * Return remote path to room invite code.
 | |
| 	 * @param string $room_id Id of room to locate QR code for.
 | |
| 	 */
 | |
| 	function room_qr_code_path_relative(string $room_id): string {
 | |
| 		global $QR_CODES_RELATIVE;
 | |
| 		return "$QR_CODES_RELATIVE/$room_id.png";
 | |
| 	}
 | |
| 
 | |
|     
 | |
| 	/**
 | |
| 	 * Fetch QR invite of the given room and return its local path.
 | |
| 	 * @param \CommunityRoom $room
 | |
|      * @return string
 | |
| 	 */
 | |
| 	function room_qr_code($room): string {
 | |
| 		$room_id = $room->get_room_identifier();
 | |
| 		$png_cached = room_qr_code_path($room_id);
 | |
| 		if (file_exists($png_cached)) {
 | |
| 			return room_qr_code_path_relative($room_id);
 | |
| 		}
 | |
| 		log_debug("Fetching QR code for $room_id.");
 | |
| 		$png = file_get_contents($room->get_invite_url());
 | |
| 		file_put_contents($png_cached, $png);
 | |
| 		return room_qr_code_path_relative($room_id);
 | |
| 	}
 | |
| 
 | |
| 	file_exists($QR_CODES) or mkdir($QR_CODES, 0755);
 | |
| ?>
 |