This repository was archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.inc.php
More file actions
56 lines (46 loc) · 1.87 KB
/
common.inc.php
File metadata and controls
56 lines (46 loc) · 1.87 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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use smtech\CanvasPest\CanvasPest;
use smtech\CanvasHack\Toolbox;
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
use Battis\DataUtilities;
define('CONFIG_FILE', __DIR__ . '/config.xml');
define('CANVAS_INSTANCE_URL', 'canvasInstanceUrl');
@session_start(); // TODO I don't feel good about suppressing warnings
/* prepare the toolbox */
if (empty($_SESSION[Toolbox::class])) {
$_SESSION[Toolbox::class] = Toolbox::fromConfiguration(CONFIG_FILE);
}
$toolbox =& $_SESSION[Toolbox::class];
/* identify the tool's Canvas instance URL */
if (empty($_SESSION[CANVAS_INSTANCE_URL])) {
if (!empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])) {
$_SESSION[CANVAS_INSTANCE_URL] =
'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
} else {
/*
* due the way that canvashack.css and canvashack.js are loaded, we
* need to fall back to the configuration file
*/
$_SESSION[CANVAS_INSTANCE_URL] =
'https://' . parse_url($toolbox->config(Toolbox::TOOL_CANVAS_API)['url'], PHP_URL_HOST);
}
}
/* force API configuration based on detected CANVAS_INSTANCE_URL */
$toolbox->setApi(new CanvasPest(
$_SESSION[CANVAS_INSTANCE_URL] . '/api/v1',
$toolbox->config(Toolbox::TOOL_CANVAS_API)['token']
));
/* configure templating engine, if we are not a CLI instance */
if (php_sapi_name() !== 'cli') {
$toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__));
$toolbox->smarty_assign([
'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__)))
]);
// FIXME convenience variable
$smarty =& $toolbox->getSmarty();
}
// FIXME convience variables until plugins are all updated
$api =& $toolbox->getAPI();
$sql =& $toolbox->getMySQL();
$customPrefs =& $toolbox->getCustomPrefs();