forked from opencaching/okapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
99 lines (77 loc) · 3.18 KB
/
Copy pathcontroller.php
File metadata and controls
99 lines (77 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace okapi;
use Exception;
use okapi\Okapi;
use okapi\Settings;
use okapi\views\menu\OkapiMenu;
#
# All HTTP requests within the /okapi/ path are redirected through this
# controller. From here we'll pass them to the right entry point (or
# display an appropriate error message).
#
# To learn more about OKAPI, see core.php.
#
$GLOBALS['rootpath'] = '../'; # this is for OC-code compatibility
require_once($GLOBALS['rootpath'].'okapi/core.php');
OkapiErrorHandler::$treat_notices_as_errors = true;
require_once($GLOBALS['rootpath'].'okapi/urls.php');
if (ob_list_handlers() == array('default output handler'))
{
# We will assume that this one comes from "output_buffering" being turned on
# in PHP config. This is very common and probably is good for most other OC
# pages. But we don't need it in OKAPI. We will just turn this off.
ob_end_clean();
}
class OkapiScriptEntryPointController
{
public static function dispatch_request($uri)
{
# Chop off the ?args=... part.
if (strpos($uri, '?') !== false)
$uri = substr($uri, 0, strpos($uri, '?'));
# Chop off everything before "/okapi/". This should work for okay for most "weird"
# server configurations. It will also address a more subtle issue described here:
# http://stackoverflow.com/questions/8040461/request-uri-unexpectedly-contains-fqdn
if (strpos($uri, "/okapi/") !== false)
$uri = substr($uri, strpos($uri, "/okapi/"));
# Make sure we're in the right directory (.htaccess should make sure of that).
if (strpos($uri, "/okapi/") !== 0)
throw new Exception("'$uri' is outside of the /okapi/ path.");
$uri = substr($uri, 7);
# Initializing internals and running pre-request cronjobs (we don't want
# cronjobs to be run before "okapi/update", for example before database
# was installed).
$allow_cronjobs = ($uri != "update");
Okapi::init_internals($allow_cronjobs);
# Checking for allowed patterns...
try
{
foreach (OkapiUrls::$mapping as $pattern => $namespace)
{
$matches = null;
if (preg_match("#$pattern#", $uri, $matches))
{
# Pattern matched! Moving on to the proper View...
array_shift($matches);
require_once($GLOBALS['rootpath']."okapi/views/$namespace.php");
$response = call_user_func_array(array('\\okapi\\views\\'.
str_replace('/', '\\', $namespace).'\\View', 'call'), $matches);
if ($response)
$response->display();
return;
}
}
}
catch (Http404 $e)
{
/* pass */
}
# None of the patterns matched OR method threw the Http404 exception.
require_once($GLOBALS['rootpath']."okapi/views/http404.php");
$response = \okapi\views\http404\View::call();
$response->display();
}
}
Okapi::gettext_domain_init();
OkapiScriptEntryPointController::dispatch_request($_SERVER['REQUEST_URI']);
Okapi::gettext_domain_restore();