This repository was archived by the owner on May 29, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcommon.inc.php
More file actions
64 lines (55 loc) · 2.12 KB
/
Copy pathcommon.inc.php
File metadata and controls
64 lines (55 loc) · 2.12 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
<?php
$requestApiDomain = (empty($_REQUEST['custom_canvas_api_domain']) ? false : $_REQUEST['custom_canvas_api_domain']);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/constants.inc.php';
use smtech\CanvasManagement\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use Battis\DataUtilities;
@session_start(); // TODO suppressing warnings is wrong
/* prepare the toolbox */
if (empty($_SESSION[Toolbox::class])) {
$_SESSION[Toolbox::class] = Toolbox::fromConfiguration(CONFIG_FILE);
}
$toolbox =& $_SESSION[Toolbox::class];
/* set the Tool Consumer's instance URL, if present */
if (empty($_SESSION[CANVAS_INSTANCE_URL])) {
if (!empty($requestApiDomain)) {
$_SESSION[CANVAS_INSTANCE_URL] = "https://{$requestApiDomain}";
} elseif (!empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])) {
$_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
} else {
$toolbox->log('Could not detect CANVAS_INSTANCE_URL');
$_SESSION[CANVAS_INSTANCE_URL] = 'https://example.com';
}
}
/* cache per-instance */
$toolbox->cache_pushKey(parse_url($_SESSION[CANVAS_INSTANCE_URL], PHP_URL_HOST));
/* Configure smarty templating */
/* FIXME this is sometimes superfluous overhead (e.g. action=config) */
$toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__));
$toolbox->getSmarty()->addStylesheet(
DataUtilities::URLfromPath(__DIR__ . '/css/canvas-management.css'),
basename(__DIR__)
);
$toolbox->smarty_assign([
'title' => $toolbox->config('TOOL_NAME'),
'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__))),
'APP_URL' => $toolbox->config('APP_URL'),
'CANVAS_INSTANCE_URL' => $_SESSION[CANVAS_INSTANCE_URL],
'navbarActive' => basename(dirname($_SERVER['REQUEST_URI'])),
'menuItems' => $toolbox->buildMenu(__DIR__, [
'.git',
'build',
'css',
'docs',
'examples',
'images',
'js',
'logs',
'node_modules',
'src',
'templates',
'tests',
'vendor'
])
]);