xref: /plugin/statistics/dispatch.php (revision 87e0f0b1298c908ddbd85655163d986a03dc53f3)
1<?php
2
3// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
4/**
5 * Statistics plugin - data logger
6 *
7 * This logger is called via JavaScript
8 *
9 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
10 * @author     Andreas Gohr <gohr@cosmocode.de>
11 */
12use dokuwiki\plugin\statistics\IgnoreException;
13use dokuwiki\ErrorHandler;
14
15if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../../../') . '/');
16define('DOKU_DISABLE_GZIP_OUTPUT', 1);
17require_once(DOKU_INC . 'inc/init.php');
18session_write_close();
19
20global $INPUT;
21
22try {
23    /** @var helper_plugin_statistics $plugin */
24    $plugin = plugin_load('helper', 'statistics');
25    $plugin->sendGIF(); // browser be done
26
27    $logger = $plugin->getLogger();
28    $logger->begin(); // triggers autologging
29
30    switch ($INPUT->str('do')) {
31        case 'v':
32            $logger->logPageView();
33            break;
34        case 'o':
35            $logger->logOutgoing();
36    }
37
38    $logger->end();
39} catch (\Exception $e) {
40    if (!$e instanceof IgnoreException) {
41        ErrorHandler::logException($e);
42    }
43}
44