<?php

function azeronFatalErrorHandler(){
        $error = error_get_last();

        // Check if it's a core/fatal error, otherwise it's a normal shutdown
        if ($error !== NULL && in_array($error['type'], array(E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, E_RECOVERABLE_ERROR))) {
	    if(isset($_SERVER["HTTP_USER_AGENT"]) && strpos($_SERVER["HTTP_USER_AGENT"], "Slackbot-LinkExpanding") === false || !isset($_SERVER["HTTP_USER_AGENT"])){
                $msg = "<!here|here>:\n" . date("Y-m-d H:i:s") . "\nType: *" .  $error["type"] . "*\nMessage: ```" . $error["message"] . "```\nFile: *" . $error["file"] . "*\nLine: *" . $error["line"] . "*\n";
                $msg .= "Request: " . $_SERVER["REQUEST_METHOD"] . " " . $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\nReferrer: " . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "none");

                $ch = curl_init();
                $payload = json_encode(["text" => $msg, 'blocks' => [[
                   "type" => "section",
                   "text" => [
                       "type" => "mrkdwn",
                       "text" => $msg
                   ],
                ], [
                   "type" => "divider"
                ]]]);

                curl_setopt($ch, CURLOPT_URL, "https://hooks.slack.com/services/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");
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_exec($ch);
                curl_close($ch);
            }
        }
}
register_shutdown_function("azeronFatalErrorHandler");

// die("We'll be back shortly!");
// Version
define('VERSION', '3.0.3.2');

// Configuration
if (is_file('config.php')) {
	require_once('config.php');
}

// Install
if (!defined('DIR_APPLICATION')) {
	header('Location: install/index.php');
	exit;
}

// Startup
require_once(DIR_SYSTEM . 'startup.php');

start('catalog');
