<?php
/*
*

 ______   _______  __   __  _______  _______  ___   _______ 
|      | |       ||  |_|  ||       ||       ||   | |       |
|  _    ||    ___||       ||   _   ||_     _||   | |       |
| | |   ||   |___ |       ||  | |  |  |   |  |   | |       |
| |_|   ||    ___||       ||  |_|  |  |   |  |   | |      _|
|       ||   |___ | ||_|| ||       |  |   |  |   | |     |_ 
|______| |_______||_|   |_||_______|  |___|  |___| |_______|
 _______  __   __  _______                                  
|       ||  |_|  ||       |                                 
|       ||       ||  _____|                                 
|       ||       || |_____                                  
|      _||       ||_____  |                                 
|     |_ | ||_|| | _____| |                                 
|_______||_|   |_||_______|                                                   
                                              
                                           
*
*
*/

/**
 * Demotic CMS is a fork of ImpressPages.
 * AUTHOR: Demotic
 * @package Demotic
 */

namespace Demotic\Gebtu\MaintenanceMode;

use Demotic\Response;

class Filter
{
    /**
     * @param \Demotic\Response $response
     * @return mixed
     */
    public static function ipSendResponse($response)
    {
        if (!ipConfig()->isEmpty()) {
            if (ipGetOption('Config.maintenanceModeActive') == 1 && ipAdminId() === false) {
    		    $configLoginUrl = ipConfig()->get('loginURI');
                if (substr(ipRequest()->getRelativePath(), 0, strlen($configLoginUrl)) != $configLoginUrl){
                    $file = file_get_contents('Demotic/Gebtu/MaintenanceMode/assets/maintenance.txt');
                    $contents = str_replace('{LOGO}', ipFileUrl('Demotic/Ui/assets/img/Demotic_CMS_logo.png'), $file);
                    return new Response($contents);
                }
    	    }
        }
	    return $response;
    }
}
