index.php 7.16 KB
Newer Older
Henning Leutz's avatar
Henning Leutz committed
1 2
<?php

3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 *  _______          _________ _______  _______  _______  _______
 * (  ___  )|\     /|\__   __/(  ___  )(  ___  )(  ____ \(  ____ )
 * | (   ) || )   ( |   ) (   | (   ) || (   ) || (    \/| (    )|
 * | |   | || |   | |   | |   | |   | || |   | || (__    | (____)|
 * | |   | || |   | |   | |   | |   | || |   | ||  __)   |     __)
 * | | /\| || |   | |   | |   | | /\| || | /\| || (      | (\ (
 * | (_\ \ || (___) |___) (___| (_\ \ || (_\ \ || (____/\| ) \ \__
 * (____\/_)(_______)\_______/(____\/_)(____\/_)(_______/|/   \__/
 *
 * @author www.pcsg.com (Henning Leutz)
 */

16

17
\error_reporting(E_ALL);
Henning Leutz's avatar
Henning Leutz committed
18

19 20
if (!\defined('QUIQQER_SYSTEM')) {
    \define('QUIQQER_SYSTEM', true);
21
}
22

Henning Leutz's avatar
Henning Leutz committed
23
// Mailto
24
if (isset($_REQUEST['_url'])
25
    && \strpos($_REQUEST['_url'], '[mailto]') !== false
26
) {
27 28
    $addr = \str_replace('[mailto]', '', $_REQUEST['_url']);
    list($user, $host) = \explode("[at]", $addr);
Henning Leutz's avatar
Henning Leutz committed
29

30
    if (isset($user) && isset($host)) {
31
        \header("Location: mailto:".$user."@".$host);
Henning Leutz's avatar
Henning Leutz committed
32 33
        exit;
    }
Henning Leutz's avatar
Henning Leutz committed
34 35
}

36
use \Symfony\Component\HttpFoundation\Response;
37 38 39 40 41

use QUI\Utils\System\Debug;
use QUI\Utils\Security\Orthos;
use QUI\System\Log;

42 43
try {
    require_once 'bootstrap.php';
Henning Leutz's avatar
Henning Leutz committed
44

45
    $Response = QUI::getGlobalResponse();
Henning Leutz's avatar
Henning Leutz committed
46

47 48
    // UTF 8 Prüfung für umlaute in url
    if (isset($_REQUEST['_url'])) {
49
        $_REQUEST['_url'] = QUI\Utils\StringHelper::toUTF8($_REQUEST['_url']);
50
    }
51

52 53
    //\QUI\Utils\System\Debug::$run = true;
    Debug::marker('index start');
54

55 56 57
    // check if one projects exists
    if (!QUI::getProjectManager()->count()) {
        $Response->setStatusCode(Response::HTTP_NOT_FOUND);
58

59 60
        $Response->setContent(
            '<div style="text-align: center; margin-top: 100px;">
61
                <img src="'.URL_BIN_DIR.'quiqqer_logo.png" style="max-width: 100%;" />
62 63
            </div>'
        );
Henning Leutz's avatar
Henning Leutz committed
64

65 66 67
        $Response->send();
        exit;
    }
68

69 70 71 72 73 74 75
    // start
    $Rewrite = QUI::getRewrite();
    $Rewrite->exec();

    QUI::getLocale()->setCurrent(
        $Rewrite->getProject()->getLang()
    );
76

Henning Leutz's avatar
Henning Leutz committed
77

78
    // switch off language
79 80 81 82
    if (isset($_REQUEST['lang']) && $_REQUEST['lang'] == 'false') {
        $Response->headers->set('X-Robots-Tag', 'noindex, nofollow');
        QUI::getLocale()->no_translation = true;
    }
Henning Leutz's avatar
Henning Leutz committed
83

84 85
    $Project = $Rewrite->getProject();
    $Site    = $Rewrite->getSite();
86
    $Engine  = QUI::getTemplateManager()->getEngine();
Henning Leutz's avatar
Henning Leutz committed
87

88
    $Site->load();
Henning Leutz's avatar
Henning Leutz committed
89

90 91 92 93
    if (isset($Locale)) {
        unset($Locale);
        $Locale = QUI::getLocale();
    }
Henning Leutz's avatar
Henning Leutz committed
94

95
    if (\defined('LOGIN_FAILED')
96 97 98 99 100 101
        || isset($_POST['login'])
        || isset($_GET['logout'])
    ) {
        $Site->setAttribute('nocache', true);
    }

102
    /**
103
     * Referral System
104 105 106
     */
    if (isset($_REQUEST['ref'])) {
        QUI::getSession()->set('ref', Orthos::clear($_REQUEST['ref']));
Henning Leutz's avatar
Henning Leutz committed
107
    }
Henning Leutz's avatar
Henning Leutz committed
108

109
    /**
110
     * maintenance work
111 112
     */
    if (QUI::conf('globals', 'maintenance')
113
        && !(QUI::getUserBySession()->getId() && QUI::getUserBySession()->isSU())
114 115 116 117 118 119 120
    ) {
        $Response->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE);
        $Response->headers->set('X-Powered-By', '');
        $Response->headers->set('Retry-After', 3600);

        $Smarty = QUI::getTemplateManager()->getEngine();

121
        $Smarty->assign([
Henning Leutz's avatar
Henning Leutz committed
122 123
            'Project'     => $Project,
            'URL_DIR'     => URL_DIR,
124 125 126 127 128
            'URL_BIN_DIR' => URL_BIN_DIR,
            'URL_LIB_DIR' => URL_LIB_DIR,
            'URL_VAR_DIR' => URL_VAR_DIR,
            'URL_OPT_DIR' => URL_OPT_DIR,
            'URL_USR_DIR' => URL_USR_DIR,
129 130
            'URL_TPL_DIR' => URL_USR_DIR.$Project->getName().'/',
            'TPL_DIR'     => OPT_DIR.$Project->getName().'/',
131
        ]);
132

133 134
        $file  = LIB_DIR.'templates/maintenance.html';
        $pfile = USR_DIR.$Project->getName().'/lib/maintenance.html';
135

136
        if (\file_exists($pfile)) {
137 138 139 140 141 142 143
            $file = $pfile;
        }

        $Response->setContent($Smarty->fetch($file));
        $Response->send();
        exit;
    }
Henning Leutz's avatar
Henning Leutz committed
144

145 146 147
    // Event onstart
    QUI::getEvents()->fireEvent('start');
    Debug::marker('objekte initialisiert');
Henning Leutz's avatar
Henning Leutz committed
148

149
    $siteCachePath = $Site->getCachePath().'/'.\md5(QUI::getRequest()->getRequestUri());
150

151 152 153 154 155 156
    // Check if user is allowed to view Site and set appropriate error code if not
    if ($Site instanceof QUI\Projects\Site\PermissionDenied) {
        $statusCode = (int)QUI::conf('globals', 'sitePermissionDeniedErrorCode');
        $Response->setStatusCode($statusCode);
    }

157 158 159

    // if cache exists, and cache should also be used
    if (CACHE
160 161 162
        && $Site->getAttribute('nocache') != true
        && !QUI::getUsers()->isAuth(QUI::getUserBySession())
    ) {
163 164 165 166 167 168 169 170 171 172 173 174 175
        try {
            $cache_content = QUI\Cache\Manager::get($siteCachePath);
            $content       = $Rewrite->outputFilter($cache_content);
            $_content      = $content;

            QUI::getEvents()->fireEvent('requestOutput', [&$_content]);

            $Response->setContent($content);
            $Response->send();
            exit;
        } catch (\Exception $Exception) {
            Log::writeDebugException($Exception);
        }
176
    }
Henning Leutz's avatar
Henning Leutz committed
177

178
    // Template Content generating
179 180
    try {
        $Template = new QUI\Template();
181
        $content  = $Template->fetchSite($Site);
Henning Leutz's avatar
Henning Leutz committed
182

183
        Debug::marker('fetch Template');
Henning Leutz's avatar
Henning Leutz committed
184

185 186 187
        $content = $Rewrite->outputFilter($content);
        $content = QUI\Control\Manager::setCSSToHead($content);
        Debug::marker('output done');
Henning Leutz's avatar
Henning Leutz committed
188

189
        QUI::getEvents()->fireEvent('requestOutput', [&$content]);
190

191 192
        $Response->setContent($content);
        Debug::marker('content done');
Henning Leutz's avatar
Henning Leutz committed
193

194 195 196 197
        // cachefile erstellen
        if ($Site->getAttribute('nocache') != true
            && !QUI::getUsers()->isAuth(QUI::getUserBySession())
        ) {
198 199 200 201 202
            try {
                QUI\Cache\Manager::set($siteCachePath, $content);
            } catch (\Exception $Exception) {
                Log::writeDebugException($Exception);
            }
203
        }
204

205
        if (Debug::$run) {
206
            Log::writeRecursive(Debug::output());
207
        }
Henning Leutz's avatar
Henning Leutz committed
208

209 210 211 212
        QUI::getSession()->set(
            'CURRENT_LANG',
            QUI::getLocale()->getCurrent()
        );
213 214 215 216 217 218
    } catch (QUI\Exception $Exception) {
        if ($Exception->getCode() == 404) {
            $Response->setStatusCode(Response::HTTP_NOT_FOUND);
        } else {
            $Response->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE);
        }
219

Henning Leutz's avatar
Henning Leutz committed
220

221
        Log::writeException($Exception, Log::LEVEL_ERROR);
222

223
        $Template = new QUI\Template();
224

225
        try {
226
            $content = $Template->fetchSite($Rewrite->getErrorSite());
227
        } catch (QUI\Exception $Exception) {
228
            $content = $Template->fetchSite($Project->firstChild());
229 230 231 232 233 234
        }

        $content = $Rewrite->outputFilter($content);
        $content = QUI\Control\Manager::setCSSToHead($content);

        $Response->setContent($content);
235 236
    }

237 238 239 240 241
    $Response->prepare(QUI::getRequest());
    $Response->send();
    exit;
} catch (\Exception $Exception) {
    // error ??
242 243
    \header('HTTP/1.1 503 Service Temporarily Unavailable');
    \header('Status: 503 Service Temporarily Unavailable');
244

245 246
    \error_log($Exception->getTraceAsString());
    \error_log($Exception->getMessage());
247

248 249
    echo \file_get_contents(
        \dirname(__FILE__).'/lib/templates/error.html'
250 251
    );
}