index.php 7.15 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
error_reporting(E_ALL);
Henning Leutz's avatar
Henning Leutz committed
17 18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Henning Leutz's avatar
Henning Leutz committed
76

77
    // switch off language
78 79 80 81
    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
82

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

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

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

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

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

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

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

120
        $Smarty->assign([
Henning Leutz's avatar
Henning Leutz committed
121 122
            'Project'     => $Project,
            'URL_DIR'     => URL_DIR,
123 124 125 126 127
            '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,
128 129
            'URL_TPL_DIR' => URL_USR_DIR.$Project->getName().'/',
            'TPL_DIR'     => OPT_DIR.$Project->getName().'/',
130
        ]);
131

132 133
        $file  = LIB_DIR.'templates/maintenance.html';
        $pfile = USR_DIR.$Project->getName().'/lib/maintenance.html';
134 135 136 137 138 139 140 141 142

        if (file_exists($pfile)) {
            $file = $pfile;
        }

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

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

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

150 151 152 153 154 155
    // 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);
    }

156 157 158

    // if cache exists, and cache should also be used
    if (CACHE
159 160 161
        && $Site->getAttribute('nocache') != true
        && !QUI::getUsers()->isAuth(QUI::getUserBySession())
    ) {
162 163 164 165 166 167 168 169 170 171 172 173 174
        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);
        }
175
    }
Henning Leutz's avatar
Henning Leutz committed
176

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

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

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

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

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

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

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

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

Henning Leutz's avatar
Henning Leutz committed
219

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

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

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

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

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

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

Henning Leutz's avatar
Henning Leutz committed
244
    error_log($Exception->getTraceAsString());
245 246 247
    error_log($Exception->getMessage());

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