|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once __DIR__ . '/vendor/autoload.php'; |
|
4
|
|
|
|
|
5
|
|
|
use smtech\CanvasPest\CanvasPest; |
|
6
|
|
|
use smtech\CanvasHack\Toolbox; |
|
7
|
|
|
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider; |
|
8
|
|
|
use Battis\DataUtilities; |
|
9
|
|
|
|
|
10
|
|
|
define('CONFIG_FILE', __DIR__ . '/config.xml'); |
|
11
|
|
|
define('CANVAS_INSTANCE_URL', 'canvasInstanceUrl'); |
|
12
|
|
|
|
|
13
|
|
|
@session_start(); // TODO I don't feel good about suppressing warnings |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/* prepare the toolbox */ |
|
16
|
|
|
if (empty($_SESSION[Toolbox::class])) { |
|
17
|
|
|
$_SESSION[Toolbox::class] = Toolbox::fromConfiguration(CONFIG_FILE); |
|
18
|
|
|
} |
|
19
|
|
|
$toolbox =& $_SESSION[Toolbox::class]; |
|
20
|
|
|
|
|
21
|
|
|
/* identify the tool's Canvas instance URL */ |
|
22
|
|
|
if (empty($_SESSION[CANVAS_INSTANCE_URL])) { |
|
23
|
|
|
if (!empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])) { |
|
24
|
|
|
$_SESSION[CANVAS_INSTANCE_URL] = |
|
25
|
|
|
'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain']; |
|
26
|
|
|
} else { |
|
27
|
|
|
/* |
|
28
|
|
|
* due the way that canvashack.css and canvashack.js are loaded, we |
|
29
|
|
|
* need to fall back to the configuration file |
|
30
|
|
|
*/ |
|
31
|
|
|
$_SESSION[CANVAS_INSTANCE_URL] = |
|
32
|
|
|
'https://' . parse_url($toolbox->config(Toolbox::TOOL_CANVAS_API)['url'], PHP_URL_HOST); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/* force API configuration based on detected CANVAS_INSTANCE_URL */ |
|
37
|
|
|
$toolbox->setApi(new CanvasPest( |
|
38
|
|
|
$_SESSION[CANVAS_INSTANCE_URL] . '/api/v1', |
|
39
|
|
|
$toolbox->config(Toolbox::TOOL_CANVAS_API)['token'] |
|
40
|
|
|
)); |
|
41
|
|
|
|
|
42
|
|
|
/* configure templating engine, if we are not a CLI instance */ |
|
43
|
|
|
if (php_sapi_name() !== 'cli') { |
|
44
|
|
|
$toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__)); |
|
45
|
|
|
$toolbox->smarty_assign([ |
|
46
|
|
|
'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__))) |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
// FIXME convenience variable |
|
50
|
|
|
$smarty =& $toolbox->getSmarty(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// FIXME convience variables until plugins are all updated |
|
54
|
|
|
$api =& $toolbox->getAPI(); |
|
55
|
|
|
$sql =& $toolbox->getMySQL(); |
|
56
|
|
|
$customPrefs =& $toolbox->getCustomPrefs(); |
|
57
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: