|  |  |  | <?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 server-relative 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 relative 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()); | 
					
						
							|  |  |  | 		if (empty($png)) { | 
					
						
							|  |  |  | 			log_warning("$room_id returned empty QR code."); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		file_put_contents($png_cached, $png); | 
					
						
							|  |  |  | 		return room_qr_code_path_relative($room_id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	file_exists($QR_CODES) or mkdir($QR_CODES, 0755); | 
					
						
							|  |  |  | ?> |